Expanding a Collapsible and pressing Tab within one frame scrolls the newly focused widget off screen
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 42/100
Direzione di ricerca
Start with Collapsible._watch_collapsed, which queues call_after_refresh(self.scroll_visible), and compare it with Screen.set_focus, which already checks if self.focused is widget before its own deferred scroll. The repro in the issue (run via asyncio with Pilot.press("enter", "tab")) is the test to reproduce against. Done means the newly focused widget stays on screen across repeated runs at low TEXTUAL_FPS, with a regression test for the one-frame Tab case; the maintainer has not yet picked between the two proposed fixes.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I hit this while writing generated tests against Textual's widgets: the same key presses ended at different scroll positions from run to run.
Expanding a Collapsible queues call_after_refresh(self.scroll_visible) (in Collapsible._watch_collapsed). If a Tab arrives before the next screen refresh, Screen.set_focus focuses the next widget and queues its own scroll with call_later. That scroll runs first, and then the Collapsible's scroll_visible runs on the refresh and scrolls back to the top of the first Collapsible. The focused widget ends up off screen.
set_focus already guards its own callback (if self.focused is widget ...), but the Collapsible's callback doesn't check whether anything has happened since.
import asyncio
import collections
import sys
import textual
from textual.app import App, ComposeResult
from textual.widgets import Collapsible, Static
class CollapsibleApp(App):
def compose(self) -> ComposeResult:
with Collapsible(title="First"):
yield Static("\n".join(f"line {n}" for n in range(40)))
with Collapsible(title="Second"):
yield Static("second contents")
async def once() -> tuple[str, float, bool]:
app = CollapsibleApp()
async with app.run_test(size=(40, 12)) as pilot:
await pilot.pause()
await pilot.press("enter", "tab")
await pilot.pause(0.5)
focused = app.focused
on_screen = focused.region.overlaps(app.screen.region)
return focused.parent.title, app.screen.scroll_y, on_screen
async def main() -> None:
runs = int(sys.argv[1]) if len(sys.argv) > 1 else 20
tally = collections.Counter()
for _ in range(runs):
tally[await once()] += 1
print(f"Textual {textual.__version__}, TEXTUAL_FPS={textual.constants.MAX_FPS}, {runs} runs")
for (title, scroll_y, on_screen), count in sorted(tally.items()):
print(f" focused={title!r} scroll_y={scroll_y} focused widget on screen={on_screen}: {count}")
asyncio.run(main())
At the default 60 fps the two keys nearly always land in the same frame window the right way round. Lowering the frame rate widens the window and shows both outcomes. Output on main (5e5b7ef), Python 3.13, macOS, 30 runs at each rate:
Textual 8.2.8, TEXTUAL_FPS=60, 30 runs
focused='Second' scroll_y=35 focused widget on screen=True: 30
Textual 8.2.8, TEXTUAL_FPS=10, 30 runs
focused='Second' scroll_y=0.0 focused widget on screen=False: 23
focused='Second' scroll_y=35 focused widget on screen=True: 7
Textual 8.2.8, TEXTUAL_FPS=2, 30 runs
focused='Second' scroll_y=0.0 focused widget on screen=False: 30
Textual 8.2.7 gives the same pattern (at 10 fps: 20 off screen, 10 on screen).
In a real terminal I think this needs both keys to arrive within one refresh, for example from a fast typist, a key macro, or input batched over SSH. In tests, Pilot.press("enter", "tab") waits only for wait_for_idle(0) between keys, not for pending call_after_refresh callbacks, so the result depends on the clock.
I expected the newly focused widget to stay in view, whatever the timing. Two ideas, either of which would fix the repro:
- in
Collapsible._watch_collapsed, skip the deferredscroll_visibleif focus has moved out of the Collapsible since it was queued, asset_focusdoes for its own callback; - or have
Pilot.presswait for the screen's pending after-refresh callbacks between keys, so tests are deterministic (this doesn't help real input).
I'm happy to send a PR for whichever you'd prefer, or to leave it if you consider the burst case acceptable.
- 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
-
author-page correction move-papers
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
acl-org/acl-anthology#10978 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
PostgreSQL results table stores labels with single quotes, and a double quote in a label fails the writeForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
HKUDS/CLI-Anything#652 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Project-N-E-K-O/N.E.K.O#3813 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Dao-AILab/flash-attention#3191 ·
I maintainer di solito rispondono entro 4 giorni