Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(RevisionDataGridView): Update RowCount while loading #11722

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ private async Task WrappedOperationAsync()
}
finally
{
if (_rerunRequested)
{
await Task.Delay(_cooldownMilliseconds);
}
await Task.Delay(_cooldownMilliseconds);

lock (_sync)
{
Expand Down
20 changes: 15 additions & 5 deletions GitUI/UserControls/RevisionGrid/RevisionDataGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ public sealed partial class RevisionDataGridView : DataGridView
{
private const int BackgroundThreadUpdatePeriod = 25;
private const int MouseWheelDeltaTimeout = 1500; // Mouse wheel idle time in milliseconds after which unconsumed wheel delta will be dropped.
private const int RowCountUpdateCoolDown = 300;

private static readonly AccessibleDataGridViewTextBoxCell _accessibleDataGridViewTextBoxCell = new();

private readonly SolidBrush _alternatingRowBackgroundBrush;
private readonly SolidBrush _authoredHighlightBrush;

private readonly BackgroundUpdater _backgroundUpdater;
private readonly BackgroundUpdater _rowCountUpdater;
private readonly BackgroundUpdater _visibleRowRangeUpdater;
private readonly Stopwatch _lastRepaint = Stopwatch.StartNew();
private readonly Stopwatch _lastScroll = Stopwatch.StartNew();
private readonly Stopwatch _consecutiveScroll = Stopwatch.StartNew();
Expand Down Expand Up @@ -90,7 +93,8 @@ public RevisionDataGridView()
{
InitFonts();

_backgroundUpdater = new BackgroundUpdater(_taskManager, UpdateVisibleRowRangeInternalAsync, BackgroundThreadUpdatePeriod);
_rowCountUpdater = new BackgroundUpdater(_taskManager, UpdateRowCountAsync, RowCountUpdateCoolDown);
_visibleRowRangeUpdater = new BackgroundUpdater(_taskManager, UpdateVisibleRowRangeInternalAsync, BackgroundThreadUpdatePeriod);

InitializeComponent();
DoubleBuffered = true;
Expand Down Expand Up @@ -592,7 +596,7 @@ private void SetRowCount(int count)
finally
{
UpdatingVisibleRows = false;
_backgroundUpdater.ScheduleExecution();
UpdateVisibleRowRange();
}
}

Expand Down Expand Up @@ -691,7 +695,13 @@ private void OnScroll()

private void TriggerRowCountUpdate()
{
UpdateVisibleRowRange();
_rowCountUpdater.ScheduleExecution();
}

private async Task UpdateRowCountAsync()
{
await _taskManager.JoinableTaskFactory.SwitchToMainThreadAsync();
SetRowCountAndSelectRowsIfReady();
}

private void UpdateVisibleRowRange()
Expand All @@ -715,7 +725,7 @@ private void UpdateVisibleRowRange()
}
}

_backgroundUpdater.ScheduleExecution();
_visibleRowRangeUpdater.ScheduleExecution();
}

private async Task UpdateVisibleRowRangeInternalAsync()
Expand Down