Skip to content

Fixes #4791 - ListView guards against out-of-range IListDataSource calls#4792

Merged
tig merged 4 commits intov2_developfrom
fix/4791-listview-out-of-range
Mar 5, 2026
Merged

Fixes #4791 - ListView guards against out-of-range IListDataSource calls#4792
tig merged 4 commits intov2_developfrom
fix/4791-listview-out-of-range

Conversation

@tig
Copy link
Copy Markdown
Collaborator

@tig tig commented Mar 4, 2026

Summary

Guards IsMarked call in OnDrawingContent with item < Source?.Count so it never passes out-of-range indices to IListDataSource implementations when the Viewport is taller than the item count\n- Refactors drawing loop to use Viewport directly instead of separate local variables

  • Adds 3 Moq-based tests verifying IsMarked, Render, and SetMark are never called with out-of-range indices

tig added 3 commits March 4, 2026 15:22
Refactored OnDrawingContent to use Viewport properties (X, Y, Width, Height) throughout, replacing the local Rectangle variable. Improved safety by checking item bounds before calling IsMarked. Replaced local focus variable with direct HasFocus property usage. Updated drawing loops and Source.Render calls to use Viewport dimensions, and removed redundant variables for clarity. These changes ensure rendering is always consistent with the current viewport and improve code readability.
…ce count (2), asserts IsMarked is never called with index >= 2

  - Draw_DoesNotCall_Render_OutOfRange — Same setup, asserts Render is never called with out-of-range index
  - Draw_DoesNotCall_SetMark_OutOfRange — Same setup with ShowMarks = true, asserts SetMark is never called with out-of-range index
Refactored the logic for determining the visual role in ListView from nested if/else statements to a switch statement using C# pattern matching on ShowMarks and MarkMultiple. This improves code clarity and maintainability while preserving existing behavior for all four selection/marking combinations. No changes to public APIs or event signatures.
@tig tig requested a review from BDisp March 4, 2026 22:26
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.64%. Comparing base (6db7f46) to head (c998484).
⚠️ Report is 1 commits behind head on v2_develop.

Files with missing lines Patch % Lines
Terminal.Gui/Views/ListView/ListView.Drawing.cs 60.00% 5 Missing and 5 partials ⚠️

❌ Your patch status has failed because the patch coverage (60.00%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@              Coverage Diff               @@
##           v2_develop    #4792      +/-   ##
==============================================
+ Coverage       77.60%   77.64%   +0.03%     
==============================================
  Files             464      464              
  Lines           45835    45822      -13     
  Branches         6859     6861       +2     
==============================================
+ Hits            35572    35579       +7     
+ Misses           8252     8235      -17     
+ Partials         2011     2008       -3     
Files with missing lines Coverage Δ
Terminal.Gui/Views/ListView/ListView.Drawing.cs 80.43% <60.00%> (+7.10%) ⬆️

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6db7f46...c998484. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Expand ListViewTests with coverage for IValue events (Value, ValueChanging, ValueChanged), keyboard mark/unmark (Ctrl+A/U), and RowRender attribute overrides. Also improve mock setup formatting. These tests ensure correct behavior for selection, event firing, and row rendering customization.
@tig tig merged commit ab86a47 into v2_develop Mar 5, 2026
12 of 14 checks passed
@tig tig deleted the fix/4791-listview-out-of-range branch March 5, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ListView.OnDrawingContent should be defensive to item < Source.Count

2 participants