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 readonly ConcurrentQueue<string> _queueMsg = new();
private volatile bool _lastMsgFilterNotAvailable; private volatile bool _lastMsgFilterNotAvailable;
private int _showLock = 0; // 0 = unlocked, 1 = locked private int _showLock = 0; // 0 = unlocked, 1 = locked
public int NumMaxMsg { get; } = 50; public int NumMaxMsg { get; } = 500;
[Reactive] [Reactive]
public string MsgFilter { get; set; } public string MsgFilter { get; set; }

View File

@ -9,8 +9,7 @@ namespace v2rayN.Desktop.Views;
public partial class MsgView : ReactiveUserControl<MsgViewModel> public partial class MsgView : ReactiveUserControl<MsgViewModel>
{ {
private const int MaxLines = 350; //private const int KeepLines = 30;
private const int KeepLines = 320;
public MsgView() public MsgView()
{ {
@ -41,20 +40,26 @@ public partial class MsgView : ReactiveUserControl<MsgViewModel>
private void ShowMsg(object msg) 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; ClearMsg();
var cutLineNumber = lc - KeepLines;
var cutLine = txtMsg.Document.GetLineByNumber(cutLineNumber);
txtMsg.Document.Remove(0, cutLine.Offset);
} }
txtMsg.AppendText(msg.ToString());
if (togScrollToEnd.IsChecked ?? true) if (togScrollToEnd.IsChecked ?? true)
{ {
txtMsg.ScrollToEnd(); txtMsg.ScrollToEnd();
} }
txtMsg.EndChange();
} }
public void ClearMsg() public void ClearMsg()