mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-14 12:29:13 +00:00
Update MsgView.xaml.cs
This commit is contained in:
parent
fafdbb42ca
commit
fff4c110ae
1 changed files with 45 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
@ -7,6 +8,9 @@ namespace v2rayN.Views;
|
||||||
|
|
||||||
public partial class MsgView
|
public partial class MsgView
|
||||||
{
|
{
|
||||||
|
private const int _maxLines = 320;
|
||||||
|
private const int _trimLines = 350;
|
||||||
|
|
||||||
public MsgView()
|
public MsgView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -47,12 +51,52 @@ public partial class MsgView
|
||||||
|
|
||||||
private void ShowMsg(object msg)
|
private void ShowMsg(object msg)
|
||||||
{
|
{
|
||||||
|
var incoming = msg?.ToString() ?? string.Empty;
|
||||||
|
var old = txtMsg.Text ?? string.Empty;
|
||||||
|
|
||||||
txtMsg.BeginChange();
|
txtMsg.BeginChange();
|
||||||
txtMsg.Text = msg.ToString();
|
|
||||||
|
if (incoming.Length >= old.Length && incoming.AsSpan(0, old.Length).SequenceEqual(old))
|
||||||
|
{
|
||||||
|
var delta = incoming.AsSpan(old.Length);
|
||||||
|
if (!delta.IsEmpty)
|
||||||
|
txtMsg.AppendText(delta.ToString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 兼容增量:如果不是全量覆盖场景,直接把 incoming 当作增量追加
|
||||||
|
if (old.Length == 0)
|
||||||
|
{
|
||||||
|
txtMsg.Text = incoming;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
txtMsg.AppendText(incoming);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 行数超过阈值才裁剪到 _maxLines
|
||||||
|
var lines = txtMsg.Text.Split(Environment.NewLine);
|
||||||
|
if (lines.Length > _trimLines)
|
||||||
|
{
|
||||||
|
var start = lines.Length - _maxLines;
|
||||||
|
if (start < 0) start = 0;
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
for (int i = start; i < lines.Length; i++)
|
||||||
|
{
|
||||||
|
sb.Append(lines[i]);
|
||||||
|
if (i < lines.Length - 1)
|
||||||
|
sb.Append(Environment.NewLine);
|
||||||
|
}
|
||||||
|
txtMsg.Text = sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
if (togScrollToEnd.IsChecked ?? true)
|
if (togScrollToEnd.IsChecked ?? true)
|
||||||
{
|
{
|
||||||
txtMsg.ScrollToEnd();
|
txtMsg.ScrollToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
txtMsg.EndChange();
|
txtMsg.EndChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue