Fixes #5127. Anchor button delimiters to edges; fix highlight continuity#5279
Merged
YourRobotOverlord merged 5 commits intoMay 9, 2026
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…t for full highlight
- Cache _interiorTextFormatter.GetDrawRegion result; pass to GetDelimiterRow
instead of recomputing it, eliminating a redundant layout pass.
- Replace Driver.AddStr(new string(' ', width)) with Driver.FillRect(drawRect)
so focus highlight covers all rows of a multi-row button, not just the text row.
- Remove redundant Region.Combine union (interior region is always a subset of drawRect).
- Add comment linking GetDecoratedText / GetInteriorText dual-path responsibility.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Button rendering when a fixed Width is larger than the button’s natural text width, ensuring the bracket delimiters render at the view edges and that focused highlighting is continuous across the full button area.
Changes:
- Override
Button.OnDrawingTextto explicitly render left/right delimiters at the content edges and pre-fill the content area with the appropriate attribute. - Introduce a dedicated
_interiorTextFormatterto center and draw only the interior text between delimiters. - Add new driver-based unit tests validating delimiter placement and focused attribute continuity for a fixed-width button.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Terminal.Gui/Views/Button.cs | Customizes Button text drawing to anchor delimiters to edges and fill the button area for continuous focus highlight. |
| Tests/UnitTestsParallelizable/Views/ButtonDrawingTests.cs | Adds tests for fixed-width delimiter placement and focused highlight continuity. |
…issing TextFormatter settings, add multi-row highlight test - Guard every _interiorTextFormatter property assignment with a value-equality check so NeedsFormat is not set spuriously on unchanged values - Mirror MultiLine, WordWrap, TabWidth, and PreserveTabs from TextFormatter to _interiorTextFormatter (previously unmirrored, potential behavioral regression) - Add Focused_FixedWidth_Button_MultiRow_Highlight_Is_Continuous test verifying all rows carry the Focus attribute when Height > 1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds Tests/Benchmarks/Views/ButtonDrawBenchmark.cs with two methods: - DrawButton_Unchanged: steady-state draw (no property changes) — the guard-optimized path where NeedsFormat is never set spuriously - DrawButton_TextChanging: text rotates each iteration — forces a real reformat, approximating the old unguarded behaviour [MemoryDiagnoser] exposes the allocation difference between the two paths, quantifying the benefit of the guards added in the preceding commit. Run: dotnet run --project Tests/Benchmarks -c Release -- --filter "*ButtonDraw*" Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced May 21, 2026
This was referenced May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Copilot Session
a98f7d36-f362-457b-8f86-885ba3e011bc
Fixes #5127.
Problem
When a
Buttonhas a fixedWidthwider than its natural size:[and]delimiters were centered with the text instead of pinned to the view edges.Focus.Solution
Override
OnDrawingTextto take direct control of rendering:[explicitly atdrawRect.X(left edge) and]atdrawRect.X + Width - 1(right edge).Driver.FillRect(drawRect)with thenormalAttr(which resolves toFocuswhen focused) before drawing text, ensuring continuous highlight across the entire button area including all rows._interiorTextFormatter.UpdateTextFormatterTextstill setsTextFormatter.Textto the full decorated string soDim.Autosizing continues to work correctly.Tests
Two new tests in
ButtonDrawingTests:FixedWidth_Anchors_Delimiters_To_Edges— verifies[and]appear at columns 0 and 9 for aWidth=10button, for bothIsDefault=falseandIsDefault=true.Focused_FixedWidth_Button_Highlight_Is_Continuous— verifies all 10 cells carryFocusorHotFocusattribute with no gaps.