From 5997a36ba11670bfe85a7b5134177734cd18dc8f Mon Sep 17 00:00:00 2001 From: Hamster Date: Mon, 25 Sep 2023 21:43:45 +0800 Subject: [PATCH] Disable smooth log scrolling when adding logs in high frequency. --- .../Controls/SessionView.axaml.LogAnalysis.cs | 19 +++++- ULogViewer/Controls/SessionView.axaml.cs | 59 +++++++++++++++++-- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/ULogViewer/Controls/SessionView.axaml.LogAnalysis.cs b/ULogViewer/Controls/SessionView.axaml.LogAnalysis.cs index 04254367..214da0ef 100644 --- a/ULogViewer/Controls/SessionView.axaml.LogAnalysis.cs +++ b/ULogViewer/Controls/SessionView.axaml.LogAnalysis.cs @@ -45,6 +45,7 @@ partial class SessionView readonly ToggleButton createLogAnalysisRuleSetButton; readonly ContextMenu createLogAnalysisRuleSetMenu; bool isPointerPressedOnLogAnalysisResultListBox; + bool isSmoothScrollingToLatestLogAnalysisResult; readonly Avalonia.Controls.ListBox keyLogAnalysisRuleSetListBox; IDisposable? logAnalysisPanelVisibilityObserverToken = EmptyDisposable.Default; readonly Avalonia.Controls.ListBox logAnalysisResultListBox; @@ -861,12 +862,21 @@ void OnLogAnalysisResultsChanged(object? sender, NotifyCollectionChangedEventArg if (this.IsScrollingToLatestLogAnalysisResultNeeded) { if (!this.scrollToLatestLogAnalysisResultAction.IsScheduled) - this.smoothScrollToLatestLogAnalysisResultAction.Schedule(ScrollingToLatestLogInterval); + { + if (this.isSmoothScrollingToLatestLogAnalysisResult) + { + this.isSmoothScrollingToLatestLogAnalysisResult = false; + this.smoothScrollToLatestLogAnalysisResultAction.Reschedule(ScrollingToLatestLogInterval); + } + else + this.smoothScrollToLatestLogAnalysisResultAction.Schedule(ScrollingToLatestLogInterval); + } } break; case NotifyCollectionChangedAction.Remove: if (session.LogAnalysis.AnalysisResults.IsEmpty()) { + this.isSmoothScrollingToLatestLogAnalysisResult = false; this.scrollToLatestLogAnalysisResultAction.Cancel(); this.smoothScrollToLatestLogAnalysisResultAction.Cancel(); } @@ -876,6 +886,7 @@ void OnLogAnalysisResultsChanged(object? sender, NotifyCollectionChangedEventArg this.scrollToLatestLogAnalysisResultAction.Cancel(); else this.scrollToLatestLogAnalysisResultAction.Schedule(ScrollingToLatestLogInterval); + this.isSmoothScrollingToLatestLogAnalysisResult = false; this.smoothScrollToLatestLogAnalysisResultAction.Cancel(); break; } @@ -1223,6 +1234,7 @@ void ScrollToLatestLogAnalysisResult(bool smoothScrolling = true) // cancel scrolling if (this.logAnalysisResultListBox.ContextMenu?.IsOpen == true || this.logMarkingMenu.IsOpen) { + this.isSmoothScrollingToLatestLogAnalysisResult = false; this.IsScrollingToLatestLogAnalysisResultNeeded = false; return; } @@ -1238,6 +1250,7 @@ void ScrollToLatestLogAnalysisResult(bool smoothScrolling = true) var distanceY = (extent.Height - viewport.Height) - currentOffset.Y; if (Math.Abs(distanceY) <= 1) { + this.isSmoothScrollingToLatestLogAnalysisResult = false; this.scrollToLatestLogAnalysisResultAction.Cancel(); this.smoothScrollToLatestLogAnalysisResultAction.Cancel(); } @@ -1246,12 +1259,14 @@ void ScrollToLatestLogAnalysisResult(bool smoothScrolling = true) || !this.Application.Configuration.GetValueOrDefault(ConfigurationKeys.UseSmoothLogScrolling)) { scrollViewer.Offset = new(currentOffset.X, currentOffset.Y + distanceY); + this.isSmoothScrollingToLatestLogAnalysisResult = false; this.scrollToLatestLogAnalysisResultAction.Cancel(); this.smoothScrollToLatestLogAnalysisResultAction.Cancel(); } else { - scrollViewer.Offset = new(currentOffset.X, currentOffset.Y + distanceY / 1.5); + scrollViewer.Offset = new(currentOffset.X, currentOffset.Y + distanceY / 2); + this.isSmoothScrollingToLatestLogAnalysisResult = true; this.scrollToLatestLogAnalysisResultAction.Cancel(); this.smoothScrollToLatestLogAnalysisResultAction.Schedule(ScrollingToLatestLogInterval); } diff --git a/ULogViewer/Controls/SessionView.axaml.cs b/ULogViewer/Controls/SessionView.axaml.cs index c855f351..5321be7c 100644 --- a/ULogViewer/Controls/SessionView.axaml.cs +++ b/ULogViewer/Controls/SessionView.axaml.cs @@ -159,7 +159,7 @@ enum LogDataSourceType const int InitScrollingToLatestLogDelay = 800; const int ScrollingToLatestLogInterval = 200; const int ScrollingToTargetLogRangeInterval = 200; - const int SmoothScrollingToLatestLogInterval = 50; + const int SmoothScrollingToLatestLogInterval = 66; // Static fields. @@ -230,6 +230,7 @@ enum LogDataSourceType bool isProcessNameNeededAfterLogProfileSet; bool isRestartingAsAdminConfirmed; bool isSelectingFileToSaveLogs; + bool isSmoothScrollingToLatestLog; bool isUriNeededAfterLogProfileSet; bool isWorkingDirNeededAfterLogProfileSet; bool keepSidePanelVisible; @@ -1266,11 +1267,13 @@ void AttachToSession(Session session) }); if (this.IsScrollingToLatestLogNeeded) { + this.isSmoothScrollingToLatestLog = false; this.scrollToLatestLogAction.Schedule(InitScrollingToLatestLogDelay); this.smoothScrollToLatestLogAction.Cancel(); } if (session.LogAnalysis.AnalysisResults.IsNotEmpty() && this.IsScrollingToLatestLogAnalysisResultNeeded) { + this.isSmoothScrollingToLatestLogAnalysisResult = false; this.scrollToLatestLogAnalysisResultAction.Schedule(ScrollingToLatestLogInterval); this.smoothScrollToLatestLogAnalysisResultAction.Cancel(); } @@ -2471,6 +2474,8 @@ void DetachFromSession(Session session) this.updateLatestDisplayedLogRangeAction.Execute(); // stop auto scrolling + this.isSmoothScrollingToLatestLog = false; + this.isSmoothScrollingToLatestLogAnalysisResult = false; this.scrollToLatestLogAction.Cancel(); this.smoothScrollToLatestLogAction.Cancel(); this.scrollToLatestLogAnalysisResultAction.Cancel(); @@ -3523,7 +3528,15 @@ void OnLogsChanged(object? sender, NotifyCollectionChangedEventArgs e) else if (this.IsScrollingToLatestLogNeeded) { if (!this.scrollToLatestLogAction.IsScheduled) - this.smoothScrollToLatestLogAction.Schedule(SmoothScrollingToLatestLogInterval); + { + if (this.isSmoothScrollingToLatestLog) + { + this.isSmoothScrollingToLatestLog = false; + this.smoothScrollToLatestLogAction.Reschedule(ScrollingToLatestLogInterval); + } + else + this.smoothScrollToLatestLogAction.Schedule(ScrollingToLatestLogInterval); + } } } else if (e.Action == NotifyCollectionChangedAction.Remove) @@ -4101,12 +4114,28 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang if (this.IsScrollingToLatestLogNeeded) { if (!this.scrollToLatestLogAction.IsScheduled) - this.smoothScrollToLatestLogAction.Schedule(SmoothScrollingToLatestLogInterval); + { + if (this.isSmoothScrollingToLatestLog) + { + this.isSmoothScrollingToLatestLog = false; + this.smoothScrollToLatestLogAction.Reschedule(ScrollingToLatestLogInterval); + } + else + this.smoothScrollToLatestLogAction.Schedule(ScrollingToLatestLogInterval); + } } if (this.IsScrollingToLatestLogAnalysisResultNeeded) { if (!this.scrollToLatestLogAnalysisResultAction.IsScheduled) - this.smoothScrollToLatestLogAnalysisResultAction.Schedule(SmoothScrollingToLatestLogInterval); + { + if (this.isSmoothScrollingToLatestLogAnalysisResult) + { + this.isSmoothScrollingToLatestLogAnalysisResult = false; + this.smoothScrollToLatestLogAnalysisResultAction.Reschedule(ScrollingToLatestLogInterval); + } + else + this.smoothScrollToLatestLogAnalysisResultAction.Schedule(ScrollingToLatestLogInterval); + } } } else if (property == DataContextProperty) @@ -4118,6 +4147,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang { if ((bool)change.NewValue!) { + this.isSmoothScrollingToLatestLog = false; this.scrollToLatestLogAction.Reschedule(ScrollingToLatestLogInterval); this.smoothScrollToLatestLogAction.Cancel(); var logProfile = (this.DataContext as Session)?.LogProfile; @@ -4130,6 +4160,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang } else { + this.isSmoothScrollingToLatestLog = false; this.scrollToLatestLogAction.Cancel(); this.smoothScrollToLatestLogAction.Cancel(); } @@ -4140,6 +4171,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang this.ScrollToLatestLogAnalysisResult(false); else { + this.isSmoothScrollingToLatestLogAnalysisResult = false; this.scrollToLatestLogAnalysisResultAction.Cancel(); this.smoothScrollToLatestLogAnalysisResultAction.Cancel(); } @@ -4165,13 +4197,22 @@ void OnSessionPropertyChanged(object? sender, PropertyChangedEventArgs e) case nameof(Session.HasLogs): if (!session.HasLogs) { + this.isSmoothScrollingToLatestLog = false; this.scrollToLatestLogAction.Cancel(); this.smoothScrollToLatestLogAction.Cancel(); } else if (this.IsScrollingToLatestLogNeeded) { if (!this.scrollToLatestLogAction.IsScheduled) - this.smoothScrollToLatestLogAction.Schedule(SmoothScrollingToLatestLogInterval); + { + if (this.isSmoothScrollingToLatestLog) + { + this.isSmoothScrollingToLatestLog = false; + this.smoothScrollToLatestLogAction.Reschedule(ScrollingToLatestLogInterval); + } + else + this.smoothScrollToLatestLogAction.Schedule(ScrollingToLatestLogInterval); + } } break; case nameof(Session.HasWorkingDirectory): @@ -4180,6 +4221,8 @@ void OnSessionPropertyChanged(object? sender, PropertyChangedEventArgs e) case nameof(Session.IsActivated): if (!session.IsActivated) { + this.isSmoothScrollingToLatestLog = false; + this.isSmoothScrollingToLatestLogAnalysisResult = false; this.scrollToLatestLogAction.Cancel(); this.smoothScrollToLatestLogAction.Cancel(); this.scrollToLatestLogAnalysisResultAction.Cancel(); @@ -4193,11 +4236,13 @@ void OnSessionPropertyChanged(object? sender, PropertyChangedEventArgs e) { if (session.LogProfile?.IsContinuousReading == true && this.IsScrollingToLatestLogNeeded) { + this.isSmoothScrollingToLatestLog = false; this.scrollToLatestLogAction.Schedule(ScrollingToLatestLogInterval); this.smoothScrollToLatestLogAction.Cancel(); } if (session.LogAnalysis.AnalysisResults.IsNotEmpty() && this.IsScrollingToLatestLogAnalysisResultNeeded) { + this.isSmoothScrollingToLatestLogAnalysisResult = false; this.scrollToLatestLogAnalysisResultAction.Schedule(ScrollingToLatestLogInterval); this.smoothScrollToLatestLogAnalysisResultAction.Cancel(); } @@ -4532,6 +4577,7 @@ void ScrollToLatestLog(bool smoothScrolling = true) if (this.logActionMenu.IsOpen || this.logMarkingMenu.IsOpen) { this.IsScrollingToLatestLogNeeded = false; + this.isSmoothScrollingToLatestLog = false; return; } @@ -4549,6 +4595,7 @@ void ScrollToLatestLog(bool smoothScrolling = true) var distanceY = targetOffset - currentOffset.Y; if (Math.Abs(distanceY) < 1) { + this.isSmoothScrollingToLatestLog = false; this.scrollToLatestLogAction.Cancel(); this.smoothScrollToLatestLogAction.Cancel(); } @@ -4557,6 +4604,7 @@ void ScrollToLatestLog(bool smoothScrolling = true) || !this.Application.Configuration.GetValueOrDefault(ConfigurationKeys.UseSmoothLogScrolling)) { scrollViewer.Offset = new(currentOffset.X, currentOffset.Y + distanceY); + this.isSmoothScrollingToLatestLog = false; this.scrollToLatestLogAction.Cancel(); this.smoothScrollToLatestLogAction.Cancel(); } @@ -4572,6 +4620,7 @@ void ScrollToLatestLog(bool smoothScrolling = true) } else scrollViewer.Offset = new(currentOffset.X, currentOffset.Y + distanceY); + this.isSmoothScrollingToLatestLog = true; this.scrollToLatestLogAction.Cancel(); this.smoothScrollToLatestLogAction.Schedule(SmoothScrollingToLatestLogInterval); }