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

Simplify revision grid repainting #11048

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 3 additions & 32 deletions GitUI/UserControls/RevisionGrid/RevisionDataGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public sealed partial class RevisionDataGridView : DataGridView
private readonly SolidBrush _authoredHighlightBrush;

private readonly BackgroundUpdater _backgroundUpdater;
private readonly Stopwatch _lastRepaint = Stopwatch.StartNew();
private readonly Stopwatch _lastScroll = Stopwatch.StartNew();
private readonly Stopwatch _consecutiveScroll = Stopwatch.StartNew();
private readonly List<ColumnProvider> _columnProviders = new();

internal RevisionGraph _revisionGraph = new();
Expand Down Expand Up @@ -92,11 +89,10 @@ public RevisionDataGridView()
}
};

Scroll += (_, _) => OnScroll();
Scroll += (_, _) => UpdateVisibleRowRange();
Resize += (_, _) => UpdateVisibleRowRange();
GotFocus += (_, _) => InvalidateSelectedRows();
LostFocus += (_, _) => InvalidateSelectedRows();
RowPrePaint += (_, _) => _lastRepaint.Restart();

CellPainting += OnCellPainting;
CellFormatting += (_, e) =>
Expand Down Expand Up @@ -273,8 +269,6 @@ private Brush GetBackground(DataGridViewElementStates state, int rowIndex, GitRe

private void OnCellPainting(object? sender, DataGridViewCellPaintingEventArgs e)
{
_lastRepaint.Restart();

Debug.Assert(_rowHeight != 0, "_rowHeight != 0");

var revision = GetRevision(e.RowIndex);
Expand Down Expand Up @@ -623,31 +617,6 @@ private void SetRowCountAndSelectRowsIfReady(int rowCount)
SelectRowsIfReady(rowCount);
}

private void OnScroll()
{
UpdateVisibleRowRange();

// When scrolling many rows within a short time, the message pump is
// flooded with WM_CTLCOLORSCROLLBAR messages and the DataGridView
// is not repainted. This happens for example when the mouse wheel
// is spinning fast (with free-spinning mouse wheels) or while dragging
// the scroll bar fast. In such cases, force a repaint to make the GUI
// feel more responsive.
if (_lastScroll.ElapsedMilliseconds > 100)
{
_consecutiveScroll.Restart();
}

if (_consecutiveScroll.ElapsedMilliseconds > 50
&& _lastRepaint.ElapsedMilliseconds > 50)
{
Update();
_lastRepaint.Restart();
}

_lastScroll.Restart();
}

private void UpdateVisibleRowRange()
{
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
Expand Down Expand Up @@ -707,6 +676,8 @@ private async Task UpdateVisibleRowRangeInternalAsync()
}
}

await this.InvokeAsync(Update);

return;

async Task UpdateGraphAsync(int fromIndex, int toIndex)
Expand Down