Repository navigation
Fixes #5728. Fixes flickering tab borders during mouse movement and focus changes - #5777
Conversation
- Regenerate shared tab borders during partial redraws - Add coverage for overlapped line regions and tab border changes
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the tab-border redraw changes.
No open issues 🎉
What changed in this PR
Addresses #5728 by regenerating clean Tabs pages’ shared borders during partial redraws, without redrawing page content or introducing a persistent cache.
Changes:
- Regenerates clean tab-page borders while skipping clean page SubViews.
- Builds overlapped line regions in one pass using horizontal spans, preserving reserved gaps.
- Adds regression coverage for partial redraws, border changes, and overlapped-region composition.
| File | Description |
|---|---|
Tests/UnitTestsParallelizable/Views/TabView/TabsDrawingTests.cs |
Tests border stability, border mutations, and limited content traversal. |
Tests/UnitTestsParallelizable/ViewBase/Draw/OverlappedLineCanvasRegionTests.cs |
Verifies composed region coordinates, reserved gaps, and rendered glyphs. |
Terminal.Gui/ViewBase/View.Drawing.LineCanvas.cs |
Replaces per-cell region unions with a single horizontal-span construction. |
Terminal.Gui/ViewBase/View.Drawing.cs |
Regenerates shared borders for clean Tabs pages without traversing their content. |
Review effort: Balanced
BDisp
left a comment
There was a problem hiding this comment.
Review of PR #5777 (Terminal.Gui): Fix tab borders disappearing during partial redraws
Verdict: approve, with optional improvements.
Approving: the approach is sound, and the tests compare partial and full redraws across all sides. The comments are small: a perf cleanup in RenderLineCanvas (comments 1–3, to be applied as a batch), a clarifying comment for the !redrawTabBorder clause, and skipping the draw indicator for clean pages. I ran the suggested changes locally and TabsDrawingTests and OverlappedLineCanvasRegionTests pass.
Suggested (in the patch)
- Skip
AdvanceDrawIndicatorfor clean pages, so the diagnostic indicator doesn't claim they were redrawn. - Keep the base region from
GetCellMapWithRegionand union only the overlapped cells, instead of discarding it and re-sorting every cell inGetRegion. - Add a comment on why
&& !redrawTabBorderis needed, since it looks redundant at a glance.
Optional
- Replace
SuperView is Tabswith a flag or virtual hook set inTabs.OnSubViewAdded, soViewdoesn't reference a subclass. Move theTabssentence out of the publicView.Drawdocs. - Add
default: throw new ArgumentException (change);to theswitchinPartialRedraw_AfterBorderChange_MatchesFullRedraw, so a typo inInlineDatacan't pass silently.
I checked these and found them fine: null cells never reach GetRegion, cellMap is a fresh dictionary, clip behavior is unchanged, DrawComplete already fires for clean views, and TitleView is always created for tab borders.
Co-authored-by: BDisp <bd.bdisp@gmail.com>
BDisp
left a comment
There was a problem hiding this comment.
Approving. The approach is sound: a clean Tabs page now re-contributes its border to the shared LineCanvas on partial redraws, without redrawing its content or subviews. The new tests compare partial and full redraws across all four tab sides and assert that content isn't redrawn.
My comments were small, and the ones the owner applied are already merged:
- A comment explaining why
&& !redrawTabBorderisn't redundant. It's a snapshot taken beforeDoDrawAdornments, which setsSubViewNeedsDraw. - Skipping
AdvanceDrawIndicatorfor clean pages, so the diagnostic indicator doesn't claim they were redrawn. - A
default: throw new ArgumentException (change);in theswitchinPartialRedraw_AfterBorderChange_MatchesFullRedraw, so a typo inInlineDatacan't pass silently.
I withdrew my suggestion to build the region from only the added cells. The owner's benchmark showed it increases allocations in all cases and only helps specific layouts, so keeping GetRegion (cellMap) is the better call.
One optional follow-up, not blocking: replace SuperView is Tabs in View.Draw with a flag or hook set in Tabs.OnSubViewAdded, so View doesn't reference a subclass.
Here is a concrete design, based on how the repo already does this. View.Drawing.cs already has internal virtual hooks, such as CollectActiveRasterImageIds, so this fits the existing style.
The idea
Today View.Draw asks "is my SuperView a Tabs?" Instead, View can ask the SuperView a generic question that Tabs answers. I'd use a virtual on the parent, not a flag set on each page in OnSubViewAdded. A virtual has no state to keep in sync. A flag set per page would have to be cleared when a page is removed or moved, or a stale true would stay behind. With a virtual, a page that is no longer in a Tabs simply stops matching.
The change
1. View.Drawing.cs: add the hook near the other internal members
/// <summary>
/// INTERNAL: When <see langword="true"/>, SubViews with <see cref="SuperViewRendersLineCanvas"/> that are
/// otherwise clean still run adornment and <see cref="LineCanvas"/> drawing (but not content or SubViews)
/// on partial redraws, so this view can composite their borders. Overridden by <see cref="Tabs"/>.
/// </summary>
internal virtual bool RedrawsCleanSubViewBorders => false;2. View.Drawing.cs: replace the hard-coded check in Draw
bool redrawTabBorder = SuperViewRendersLineCanvas && SuperView is { RedrawsCleanSubViewBorders: true } && !NeedsDraw && !SubViewNeedsDraw;You could rename the variable to redrawCleanBorder, but keeping the name leaves the existing comments valid.
3. Tabs.cs: opt in
internal override bool RedrawsCleanSubViewBorders => true;4. Docs: remove the sentence "Clean pages in Tabs also regenerate their shared borders…" from the public View.Draw remarks. The explanation now lives in the internal member's doc comment, so the public docs no longer mention a subclass.
- Nothing else changes.
redrawTabBorder's snapshot semantics and the two places that use it (&& !redrawTabBorderand the indicator gating) stay exactly as they are. - Both are in the same assembly, so
internal virtualand the override need no new public API orInternalsVisibleTo. - The existing tests cover it.
PartialRedraw_PreservesTabBordersandPartialRedraw_AfterBorderChange_MatchesFullRedraw, which includes theRemoveTabcase, are exactly what would catch a mistake here. - I have compiled and run this and both test files,, TabsDrawingTests
andOverlappedLineCanvasRegionTests` pass.
I've made the patch, pr5777-subview-border-hook.patch. It's a fresh patch, independent of the earlier one, and it applies cleanly to PR head 8ae286e.
What it changes
View.Drawing.cs:- Adds
internal virtual bool RedrawsCleanSubViewBorders => false;next to the other internal hooks. - Changes the check from
SuperView is TabstoSuperView is { RedrawsCleanSubViewBorders: true }. - Removes the "Clean pages in
Tabs…" sentence from the publicView.Drawremarks. The explanation now lives in the hook's doc comment.
- Adds
Tabs.cs: addsinternal override bool RedrawsCleanSubViewBorders => true;just aboveOnSubViewAdded.
Nothing else changes, so the snapshot logic around redrawTabBorder is untouched.
How to apply and test
From a clean checkout of the PR branch:
git apply --check /path/to/pr5777-subview-border-hook.patch
git apply /path/to/pr5777-subview-border-hook.patch
dotnet test Tests/UnitTestsParallelizable --filter "FullyQualifiedName~TabsDrawingTests|FullyQualifiedName~OverlappedLineCanvasRegionTests"If the owner has pushed new commits, such as the ones that merged the comment, the draw-indicator gating and the test default: throw, your branch will differ from 8ae286e. This patch should still apply, because those edits are further down Draw. If git apply --check complains, use git apply --3way, or paste the error here.
Two things to watch for
- Build warnings: the public docs no longer mention
Tabs, but the internal member's doc does, using<see cref="Tabs"/>the same way the old doc did. That should resolve the same way, but doc-warning settings are the likeliest place for a build error. - Test results: all
TabsDrawingTestscases, includingRemoveTab, should pass unchanged. If any fail, tell me which one, since that would point to a behavior difference I missed.
BDisp
left a comment
There was a problem hiding this comment.
Approving. A clean Tabs page now re-contributes its border to the shared LineCanvas on partial redraws, without redrawing its content or SubViews. The new tests compare partial and full redraws across all four tab sides and assert that content isn't redrawn.
All of my earlier comments have been addressed:
- The
!redrawCleanBorderclause now has a comment explaining why it isn't redundant: the snapshot is taken beforeDoDrawAdornmentssetsSubViewNeedsDraw. AdvanceDrawIndicatoris skipped for border-only passes.- The test
switchhas adefault:throw. Viewno longer referencesTabs: the check is nowSuperView is { RedrawsCleanSubViewBorders: true }, overridden inTabs, and the publicView.Drawdocs are generic. TheredrawCleanBorderrename suits the generic check.
I withdrew my earlier suggestion to build the region from only the added cells, since the owner's benchmark showed it increases allocations.
Mouse movement and focus changes can make tab corners, junctions, and the selected tab's opening change during partial redraws. Clean pages no longer contribute their shared borders after the previous draw consumed their canvases.
This alternative to #5729 regenerates clean Tabs pages' adornments during composition, while skipping their clean page SubViews. It adds no persistent cache, invalidation keys, subscriptions, or public APIs. The base drawing code queries the stateless internal
RedrawsCleanSubViewBordershook;Tabsopts in with an override. No page flag needs cleanup when views are removed or moved. Production changes are limited toView.Drawing.cs,View.Drawing.LineCanvas.cs, andTabs.cs.Regenerating borders alone was too expensive. The accompanying optimization builds the overlapped line region once using the existing horizontal-span helper instead of normalizing a region for every border cell. Reserved gaps remain excluded; drawing order and clipping are preserved.
Validation
The final hook refactor passed a Release test-project build, all 132 Tabs tests, and six overlapped-canvas tests. A paired six-case benchmark in both orders found no systematic timing or allocation regression; glyph checks and traversal counts were unchanged. Timing variation does not establish a speedup.
ViewDrawingClippingTests.Draw_WithBorderSubView_DrawsCorrectlyand the three terminal-colorSchemeColorNoneDerivationTests.Focus_*cases. The new region test was added afterward and passed separately.Performance
Local Release in-memory benchmark, 160×30 screen, one dirty button, 30 warmups, calibrated iterations, median of five batches. Real driver I/O and tiered compilation disabled; no tests or recordings ran concurrently. Both baseline/candidate orders were exercised. These results exclude layout and terminal output and are not terminal frame-rate measurements.
All six candidate cases were faster and allocated less than both baseline runs. Control visits remained identical (1 or 50 per redraw), with zero page-content redraws. The buggy baseline requires
SKIP_GLYPH_CHECK=1; the alternative passes initial/partial/full glyph-equality checks.Harness and raw measurements. Copy the harness files into
artifacts/tab-redraw/perf/in a source checkout, then run:Scope
Border work still scales with tab count. This deliberately fixes Tabs rather than introducing a general retained shared-canvas architecture; preservation of arbitrary content-generated lines on SubView-only passes is outside this change.
Before


After
To pull down this PR locally