TextArea gutter is too narrow when `line_number_start` is negative

Aperta Adatta ai principianti
#6,787 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
frontend

Direzione di ricerca

Inizia dal widget TextArea, dove gutter_width viene calcolato dall'ultimo numero di riga e render_line disegna il margine usando line_number_start. Esegui la riproduzione nella issue per vedere la riga disallineata -10. È completato quando il margine viene dimensionato in base al più largo tra il primo e l'ultimo numero, in modo che tutte le righe inizino il testo nella stessa colonna, con un test che copra gli inizi negativi. Prima conferma con un maintainer se gli inizi negativi sono supportati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
37.7k
Fork
1.5k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Textualize/textual

Tutte le issue di Textualize/textual

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.