`MaskedInput` crashes with `AssertionError` when you type or delete with the cursor on a separator
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 77/100
Direzione di ricerca
Leggi MaskedInput e i suoi metodi _Template.insert_text_at_cursor e _Template.delete_at_position, insieme ai test esistenti dei widget. Riproduci il crash usando run_test() e pilot.press() con la maschera e il valore forniti. Completato quando digitare e cancellare nelle posizioni dei separatori non causa più un'asserzione e il comportamento atteso descritto è coperto dai test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I hit this while writing generated tests against Textual's widgets.
If the cursor of a MaskedInput rests on a separator, typing a character or pressing delete crashes the app with an AssertionError. The easiest way to get there is a value that stops just before a separator, such as value="1234" for 9999-9999: the cursor goes to the end of the value, which is the -.
from textual.app import App, ComposeResult
from textual.widgets import MaskedInput
class MaskedApp(App):
def compose(self) -> ComposeResult:
yield MaskedInput("9999-9999", value="1234")
if __name__ == "__main__":
MaskedApp().run()
Press end (or pass select_on_focus=False), then type 5.
Expected: the value becomes 1234-5, as it does when you type 12345 from empty.
Actual:
│ ❱ 247 │ │ │ assert _CharFlags.SEPARATOR not in char_definition.flags │
AssertionError
I tried a few ways in, headless with run_test() and pilot.press(). Each line is the keys pressed and what happened:
9999-9999, value 1234, end, 5: AssertionError:
9999-9999, value 1234, select_on_focus=False, 5: AssertionError:
99/99, value 12, end, 3: AssertionError:
9999-9999, value 1234, end, delete: AssertionError:
(999) 999-9999, value (12, select_on_focus=False, home, 5: AssertionError:
9999-9999, value 1234-, end, 5 (control): value='1234-5' cursor=6
The same output on Textual 8.2.7 and on main at 5e5b7ef.
_Template.insert_text_at_cursor and _Template.delete_at_position both assert that the cursor isn't on a separator, but several things can leave it there:
- the cursor at the end of a value that stops just before a separator (as above, or after setting
valuein code); - a click past the end of such a value (
_on_clickmoves right off a separator, but the cursor is then clamped back to the end of the value); - home on a template that starts with a separator: it moves to 0, which is the separator. TomJGooding mentioned this one in the discussion on #6287.
I think the simplest fix is for those two methods to step over separators at the cursor instead of asserting. Typing then fills in the separator and goes on, as it does after the last character before a separator, and delete removes the next editable character, or does nothing at the end of the value. I'm happy to send a PR with tests.
- Lingua principale
- Python
- Stelle
- 37.7k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Textualize/textual
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6790 · 2 commenti ·
-
Markdown table of contents: the node added for a skipped heading level shows the wrong numeralAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
Textualize/textual#6789 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6787 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6782 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
Textualize/textual#6778 · 1 commento ·
Tutte le issue di Textualize/textual
Issue simili
-
Internal ErrorApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
frappe/frappe_docker#2071 ·
I maintainer di solito rispondono entro 1 giorno
-
bug python
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
traceloop/openllmetry#4717 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Apertacomp/desktop P2 type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NousResearch/hermes-agent#157702 ·
I maintainer di solito rispondono entro 1 giorno
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenForse già presa @BahaaMattar l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
I maintainer di solito rispondono entro 1 giorno