Optimize and improve MsgView

pull/8042/head
2dust 2025-09-26 15:07:33 +08:00
parent 21a773f400
commit 326bf334e7
2 changed files with 14 additions and 9 deletions

View File

@ -12,7 +12,7 @@ public class MsgViewModel : MyReactiveObject
private readonly ConcurrentQueue<string> _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; }

View File

@ -9,8 +9,7 @@ namespace v2rayN.Desktop.Views;
public partial class MsgView : ReactiveUserControl<MsgViewModel>
{
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<MsgViewModel>
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()