mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 20:09:12 +00:00
Update MsgView.axaml.cs
This commit is contained in:
parent
94e86c03c9
commit
82b69933f3
1 changed files with 18 additions and 3 deletions
|
@ -11,6 +11,7 @@ namespace v2rayN.Desktop.Views;
|
||||||
public partial class MsgView : ReactiveUserControl<MsgViewModel>
|
public partial class MsgView : ReactiveUserControl<MsgViewModel>
|
||||||
{
|
{
|
||||||
private readonly ScrollViewer _scrollViewer;
|
private readonly ScrollViewer _scrollViewer;
|
||||||
|
private int _lastShownLength = 0;
|
||||||
|
|
||||||
public MsgView()
|
public MsgView()
|
||||||
{
|
{
|
||||||
|
@ -44,11 +45,25 @@ public partial class MsgView : ReactiveUserControl<MsgViewModel>
|
||||||
|
|
||||||
private void ShowMsg(object msg)
|
private void ShowMsg(object msg)
|
||||||
{
|
{
|
||||||
txtMsg.Text = msg.ToString();
|
var newText = msg?.ToString() ?? string.Empty;
|
||||||
if (togScrollToEnd.IsChecked ?? true)
|
|
||||||
|
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()
|
public void ClearMsg()
|
||||||
|
|
Loading…
Reference in a new issue