Skip to content

Fixes #5728. Fixes flickering tab borders during mouse movement and focus changes - #5777

Merged
YourRobotOverlord merged 5 commits into
tui-cs:developfrom
YourRobotOverlord:fix/5728-regenerate-tab-borders
Nov 7, 2026
Merged

YourRobotOverlord merged 5 commits into
tui-cs:developfrom
YourRobotOverlord:fix/5728-regenerate-tab-borders

Conversation

@YourRobotOverlord

@YourRobotOverlord YourRobotOverlord commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

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 RedrawsCleanSubViewBorders hook; Tabs opts in with an override. No page flag needs cleanup when views are removed or moved. Production changes are limited to View.Drawing.cs, View.Drawing.LineCanvas.cs, and Tabs.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.

  • Release solution build passed, with no warnings in changed files.
  • 132 Tabs tests passed. The 27 reused regression cases produce 14 failures against unchanged develop.
  • Six overlapped-canvas tests passed, including a new test checking every region coordinate and reserved gaps.
  • Full parallel suite: 18,533 passed, 16 skipped, four failed. All four reproduce with unchanged develop: ViewDrawingClippingTests.Draw_WithBorderSubView_DrawsCorrectly and the three terminal-color SchemeColorNoneDerivationTests.Focus_* cases. The new region test was added afterward and passed separately.
  • Nonparallel: 35 passed. Integration: 439 passed.
  • Recorded hover, focus navigation, and tab switching in a PTY; inspected cast output and GIF frames.

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.

Tabs Controls/page Develop ms/redraw Alternative ms/redraw Develop MiB/redraw Alternative MiB/redraw
1 1 19.44 0.82 38.09 0.94
1 50 22.96 1.60 39.12 2.09
4 1 21.80 2.61 38.20 2.50
4 50 21.52 3.92 39.42 3.89
20 1 21.63 14.45 39.46 12.02
20 50 26.50 16.95 41.42 14.36

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:

dotnet build artifacts/tab-redraw/perf/TabRedrawPerf.csproj -c Release
$env:DisableRealDriverIO = '1'
$env:DOTNET_TieredCompilation = '0'
dotnet artifacts/tab-redraw/perf/bin/Release/net10.0/Benchmarks.dll artifacts/tab-redraw/perf/rerun.json

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
WindowsTerminal_VWXCaabQTE
After
WindowsTerminal_cw54xuMBEN

To pull down this PR locally

git remote add copilot https://github.com/YourRobotOverlord/Terminal.Gui.git
git fetch copilot fix/5728-regenerate-tab-borders
git checkout copilot/fix/5728-regenerate-tab-borders

- Regenerate shared tab borders during partial redraws
- Add coverage for overlapped line regions and tab border changes
@YourRobotOverlord YourRobotOverlord changed the title Fixes #5728. Regenerate tab borders without caching Fixes #5728. Fixes flickering tab borders during mouse movement and focus changes Nov 6, 2026
@YourRobotOverlord
YourRobotOverlord requested a balanced review from Copilot November 6, 2026 03:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 BDisp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AdvanceDrawIndicator for clean pages, so the diagnostic indicator doesn't claim they were redrawn.
  • Keep the base region from GetCellMapWithRegion and union only the overlapped cells, instead of discarding it and re-sorting every cell in GetRegion.
  • Add a comment on why && !redrawTabBorder is needed, since it looks redundant at a glance.

Optional

  • Replace SuperView is Tabs with a flag or virtual hook set in Tabs.OnSubViewAdded, so View doesn't reference a subclass. Move the Tabs sentence out of the public View.Draw docs.
  • Add default: throw new ArgumentException (change); to the switch in PartialRedraw_AfterBorderChange_MatchesFullRedraw, so a typo in InlineData can'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.

Comment thread Terminal.Gui/ViewBase/View.Drawing.cs Resolved
Comment thread Terminal.Gui/ViewBase/View.Drawing.cs Resolved
@tig
tig requested a balanced review from Copilot November 7, 2026 13:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the changes that stabilize tab borders during partial redraws.

No open issues 🎉

Review effort: Balanced

@BDisp BDisp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 && !redrawTabBorder isn't redundant. It's a snapshot taken before DoDrawAdornments, which sets SubViewNeedsDraw.
  • Skipping AdvanceDrawIndicator for clean pages, so the diagnostic indicator doesn't claim they were redrawn.
  • A default: throw new ArgumentException (change); in the switch in PartialRedraw_AfterBorderChange_MatchesFullRedraw, so a typo in InlineData can'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 (&& !redrawTabBorder and the indicator gating) stay exactly as they are.
  • Both are in the same assembly, so internal virtual and the override need no new public API or InternalsVisibleTo.
  • The existing tests cover it. PartialRedraw_PreservesTabBorders and PartialRedraw_AfterBorderChange_MatchesFullRedraw, which includes the RemoveTab case, are exactly what would catch a mistake here.
  • I have compiled and run this and both test files,, TabsDrawingTestsandOverlappedLineCanvasRegionTests` 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 Tabs to SuperView is { RedrawsCleanSubViewBorders: true }.
    • Removes the "Clean pages in Tabs…" sentence from the public View.Draw remarks. The explanation now lives in the hook's doc comment.
  • Tabs.cs: adds internal override bool RedrawsCleanSubViewBorders => true; just above OnSubViewAdded.

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 TabsDrawingTests cases, including RemoveTab, should pass unchanged. If any fail, tell me which one, since that would point to a behavior difference I missed.

pr5777-subview-border-hook.patch

@BDisp BDisp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 !redrawCleanBorder clause now has a comment explaining why it isn't redundant: the snapshot is taken before DoDrawAdornments sets SubViewNeedsDraw.
  • AdvanceDrawIndicator is skipped for border-only passes.
  • The test switch has a default: throw.
  • View no longer references Tabs: the check is now SuperView is { RedrawsCleanSubViewBorders: true }, overridden in Tabs, and the public View.Draw docs are generic. The redrawCleanBorder rename 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.

@YourRobotOverlord
YourRobotOverlord merged commit 2f05ef9 into tui-cs:develop Nov 7, 2026
14 checks passed
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.

Tabs borders change during mouse movement and partial redraws

4 participants