From 82b69933f35dd7bab0db3100da4475e27b1f4c21 Mon Sep 17 00:00:00 2001 From: JieXu Date: Thu, 25 Sep 2025 05:08:39 +0800 Subject: [PATCH] Update MsgView.axaml.cs --- v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs index e2d21101..7ce0ad07 100644 --- a/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs @@ -11,6 +11,7 @@ namespace v2rayN.Desktop.Views; public partial class MsgView : ReactiveUserControl { private readonly ScrollViewer _scrollViewer; + private int _lastShownLength = 0; public MsgView() { @@ -44,11 +45,25 @@ public partial class MsgView : ReactiveUserControl private void ShowMsg(object msg) { - txtMsg.Text = msg.ToString(); - if (togScrollToEnd.IsChecked ?? true) + var newText = msg?.ToString() ?? string.Empty; + + if (txtMsg.Text is { } old && newText.Length >= _lastShownLength && newText.AsSpan(0, _lastShownLength).SequenceEqual(old)) { - _scrollViewer?.ScrollToEnd(); + var delta = newText.AsSpan(_lastShownLength); + if (!delta.IsEmpty) + txtMsg.Text += delta.ToString(); } + else + { + txtMsg.Text = newText; + } + + _lastShownLength = txtMsg.Text.Length; + + if (togScrollToEnd.IsChecked ?? true) + Avalonia.Threading.Dispatcher.UIThread.Post( + () => _scrollViewer?.ScrollToEnd(), + Avalonia.Threading.DispatcherPriority.Render); } public void ClearMsg()