Update MsgView.axaml.cs

This commit is contained in:
JieXu 2025-09-25 05:08:39 +08:00 committed by GitHub
parent 94e86c03c9
commit 82b69933f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,6 +11,7 @@ namespace v2rayN.Desktop.Views;
public partial class MsgView : ReactiveUserControl<MsgViewModel>
{
private readonly ScrollViewer _scrollViewer;
private int _lastShownLength = 0;
public MsgView()
{
@ -44,11 +45,25 @@ public partial class MsgView : ReactiveUserControl<MsgViewModel>
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()