Skip to content

Commit

Permalink
Disable smooth log scrolling when adding logs in high frequency.
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster620 committed Sep 26, 2023
1 parent e8dcfce commit 5997a36
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
19 changes: 17 additions & 2 deletions ULogViewer/Controls/SessionView.axaml.LogAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -876,6 +886,7 @@ void OnLogAnalysisResultsChanged(object? sender, NotifyCollectionChangedEventArg
this.scrollToLatestLogAnalysisResultAction.Cancel();
else
this.scrollToLatestLogAnalysisResultAction.Schedule(ScrollingToLatestLogInterval);
this.isSmoothScrollingToLatestLogAnalysisResult = false;
this.smoothScrollToLatestLogAnalysisResultAction.Cancel();
break;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
}
Expand All @@ -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);
}
Expand Down
59 changes: 54 additions & 5 deletions ULogViewer/Controls/SessionView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -230,6 +230,7 @@ enum LogDataSourceType
bool isProcessNameNeededAfterLogProfileSet;
bool isRestartingAsAdminConfirmed;
bool isSelectingFileToSaveLogs;
bool isSmoothScrollingToLatestLog;
bool isUriNeededAfterLogProfileSet;
bool isWorkingDirNeededAfterLogProfileSet;
bool keepSidePanelVisible;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -4130,6 +4160,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
}
else
{
this.isSmoothScrollingToLatestLog = false;
this.scrollToLatestLogAction.Cancel();
this.smoothScrollToLatestLogAction.Cancel();
}
Expand All @@ -4140,6 +4171,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
this.ScrollToLatestLogAnalysisResult(false);
else
{
this.isSmoothScrollingToLatestLogAnalysisResult = false;
this.scrollToLatestLogAnalysisResultAction.Cancel();
this.smoothScrollToLatestLogAnalysisResultAction.Cancel();
}
Expand All @@ -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):
Expand All @@ -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();
Expand All @@ -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();
}
Expand Down Expand Up @@ -4532,6 +4577,7 @@ void ScrollToLatestLog(bool smoothScrolling = true)
if (this.logActionMenu.IsOpen || this.logMarkingMenu.IsOpen)
{
this.IsScrollingToLatestLogNeeded = false;
this.isSmoothScrollingToLatestLog = false;
return;
}

Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 5997a36

Please sign in to comment.