TextArea gutter is too narrow when `line_number_start` is negative
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start with the TextArea widget, where gutter_width is computed from the last line number and render_line draws the gutter using line_number_start. Run the reproduction in the issue to see the misaligned -10 row. Done means the gutter is sized from the widest of the first and last numbers, so all rows start the text in the same column, with a test covering negative starts. Confirm first with a maintainer whether negative starts are supported.
Written by the indexing model from the issue text.
Description
Hi! I hit this while writing generated tests against Textual's widgets.
TextArea.gutter_width is sized from the last line number only. With a negative line_number_start the first number can be the longest (-10 against -8), so its line is pushed one cell to the right.
import asyncio
import textual
from textual.app import App, ComposeResult
from textual.widgets import TextArea
class GutterApp(App):
def compose(self) -> ComposeResult:
yield TextArea("aaa\nbbb\nccc", show_line_numbers=True, line_number_start=-10)
async def main() -> None:
app = GutterApp()
async with app.run_test(size=(30, 7)) as pilot:
text_area = app.query_one(TextArea)
await pilot.pause()
print("gutter_width:", text_area.gutter_width)
for y in range(3):
print(repr(text_area.render_line(y).text.rstrip()))
print("Textual", textual.__version__)
asyncio.run(main())
Output on Textual 8.2.7 (and the same on main at 5e5b7ef):
gutter_width: 4
'-10 aaa'
'-9 bbb'
'-8 ccc'
I expected the text to start in the same column on every line. I'm not sure negative starts are meant to be supported (nothing rejects them, and -1, 0, 1 hits the same thing), so is this worth fixing? If so, sizing the gutter from the longer of the first and last numbers is a small change, and I have it with a test.
- Dominant language
- Python
- Stars
- 37.7k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Textualize/textual
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6790 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Textualize/textual#6789 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6782 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Textualize/textual#6778 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Textualize/textual#6777 · 1 comment ·
All issues in Textualize/textual
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day