Update MsgView.axaml.cs

This commit is contained in:
JieXu 2025-09-26 03:07:53 +08:00 committed by GitHub
parent c3ab3532fb
commit 6a4a35bffe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,12 +10,13 @@ namespace v2rayN.Desktop.Views;
public partial class MsgView : ReactiveUserControl<MsgViewModel>
{
private readonly ScrollViewer _scrollViewer;
private const int MaxLines = 500;
public MsgView()
{
InitializeComponent();
_scrollViewer = this.FindControl<ScrollViewer>("msgScrollViewer");
txtMsg.Options.AllowScrollBelowDocument = false;
ViewModel = new MsgViewModel(UpdateViewHandler);
@ -44,12 +45,20 @@ public partial class MsgView : ReactiveUserControl<MsgViewModel>
private void ShowMsg(object msg)
{
// txtMsg.Text = msg.ToString();
txtMsg.AppendText(msg.ToString());
var doc = txtMsg.Document;
if (doc.LineCount > MaxLines)
{
int removeCount = doc.LineCount - MaxLines;
var line = doc.GetLineByNumber(removeCount);
int removeUpTo = line.EndOffset;
doc.Remove(0, removeUpTo);
}
if (togScrollToEnd.IsChecked ?? true)
{
txtMsg.ScrollToEnd();
_scrollViewer?.ScrollToEnd();
}
}