From 326bf334e761d90a8b871f7acbfd231787d75095 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:07:33 +0800 Subject: [PATCH] Optimize and improve MsgView --- v2rayN/ServiceLib/ViewModels/MsgViewModel.cs | 2 +- v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs | 21 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs index 8b3467bd..e9d89b94 100644 --- a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs @@ -12,7 +12,7 @@ public class MsgViewModel : MyReactiveObject private readonly ConcurrentQueue _queueMsg = new(); private volatile bool _lastMsgFilterNotAvailable; private int _showLock = 0; // 0 = unlocked, 1 = locked - public int NumMaxMsg { get; } = 50; + public int NumMaxMsg { get; } = 500; [Reactive] public string MsgFilter { get; set; } diff --git a/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs index f7b2f9b9..637579ee 100644 --- a/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs @@ -9,8 +9,7 @@ namespace v2rayN.Desktop.Views; public partial class MsgView : ReactiveUserControl { - private const int MaxLines = 350; - private const int KeepLines = 320; + //private const int KeepLines = 30; public MsgView() { @@ -41,20 +40,26 @@ public partial class MsgView : ReactiveUserControl private void ShowMsg(object msg) { - txtMsg.AppendText(msg.ToString()); + txtMsg.BeginChange(); - if (txtMsg.Document.LineCount > MaxLines) + //var lineCount = txtMsg.LineCount; + //if (lineCount > ViewModel?.NumMaxMsg) + //{ + // var cutLine = txtMsg.Document.GetLineByNumber(lineCount - KeepLines); + // txtMsg.Document.Remove(0, cutLine.Offset); + //} + if (txtMsg.LineCount > ViewModel?.NumMaxMsg) { - var lc = txtMsg.Document.LineCount; - var cutLineNumber = lc - KeepLines; - var cutLine = txtMsg.Document.GetLineByNumber(cutLineNumber); - txtMsg.Document.Remove(0, cutLine.Offset); + ClearMsg(); } + txtMsg.AppendText(msg.ToString()); if (togScrollToEnd.IsChecked ?? true) { txtMsg.ScrollToEnd(); } + + txtMsg.EndChange(); } public void ClearMsg()