HelpPanel shows the wrong widget's help if focus moved while the app was blurred or a modal was open
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 58/100
Línea de trabajo
Start with HelpPanel.update_help, which returns early while the app is blurred or its screen is inactive, and see how Screen.bindings_updated_signal is published from App._on_app_focus, App._on_app_blur and _watch_stack_updates. Run the issue's two reproduction scripts, blur_case and modal_case. Done when the panel shows the help of the widget focused after AppFocus or after a modal is popped, and the existing help panel tests still pass.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi! I hit this while writing generated tests against Textual's widgets.
HelpPanel.update_help returns early while the app doesn't have focus, or while its screen isn't the active one. That makes sense, but nothing runs it again when the app gets focus back or the screen is resumed. So if focus moves in the meantime, the panel keeps the help of the widget that was focused before.
Two ways to see it:
- The terminal loses focus (
AppBlur), the app moves focus (a timer, a worker, a message), then the terminal gets focus back (AppFocus). - Focus moves on a screen while a modal covers it, then the modal is popped.
import asyncio
import textual
from textual import events
from textual.app import App, ComposeResult
from textual.screen import ModalScreen
from textual.widgets import Button, HelpPanel, Input, Markdown
class First(Input):
HELP = "Help for the **first** input."
class Second(Input):
HELP = "Help for the **second** input."
class Modal(ModalScreen):
def compose(self) -> ComposeResult:
yield Button("OK")
class HelpApp(App):
def compose(self) -> ComposeResult:
yield First(id="first")
yield Second(id="second")
def on_mount(self) -> None:
self.action_show_help_panel()
def shown_help(app: App) -> str:
return app.screen.query_one(HelpPanel).query_one(Markdown).source
async def blur_case() -> None:
app = HelpApp()
async with app.run_test() as pilot:
await pilot.pause()
app.query_one("#first").focus()
await pilot.pause()
print("focused first: ", repr(shown_help(app)))
# The terminal loses focus, the app moves focus, the terminal gets focus back.
app.post_message(events.AppBlur())
await pilot.pause()
app.query_one("#second").focus()
await pilot.pause()
app.post_message(events.AppFocus())
await pilot.pause()
print("after refocus: ", app.focused.id, repr(shown_help(app)))
async def modal_case() -> None:
app = HelpApp()
async with app.run_test() as pilot:
await pilot.pause()
app.query_one("#first").focus()
await pilot.pause()
base = app.screen
app.push_screen(Modal())
await pilot.pause()
# Focus moves on the base screen while the modal covers it.
base.set_focus(base.query_one("#second"))
await pilot.pause()
app.pop_screen()
await pilot.pause()
print("after pop: ", app.focused.id, repr(shown_help(app)))
print("Textual", textual.__version__)
asyncio.run(blur_case())
asyncio.run(modal_case())
Output on Textual 8.2.7 (main at 5e5b7ef is the same):
Textual 8.2.7
focused first: 'Help for the **first** input.'
after refocus: second 'Help for the **first** input.'
after pop: second 'Help for the **first** input.'
Expected: once the app has focus again, or the screen is resumed, the panel shows the help for the widget that is focused then (Help for the **second** input.).
KeyPanel and Footer don't have this problem, because they update from Screen.bindings_updated_signal. That signal is published on AppFocus and AppBlur (App._on_app_focus / _on_app_blur call refresh_bindings) and when a screen is resumed (_watch_stack_updates). I think HelpPanel could listen to it too, and catch up there. I'm happy to send a PR.
- Lenguaje dominante
- Python
- Estrellas
- 37.7k
- Forks
- 1.5k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Textualize/textual
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6790 · 2 comentarios ·
-
Markdown table of contents: the node added for a skipped heading level shows the wrong numeralAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Textualize/textual#6789 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6787 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6782 · 1 comentario ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Textualize/textual#6778 · 1 comentario ·
Todos los issues de Textualize/textual
Issues similares
-
Internal ErrorAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
frappe/frappe_docker#2071 ·
Los mantenedores suelen responder en 1 día
-
bug python
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
traceloop/openllmetry#4717 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Abiertocomp/desktop P2 type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NousResearch/hermes-agent#157702 ·
Los mantenedores suelen responder en 1 día
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenPosiblemente ocupada @BahaaMattar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
Los mantenedores suelen responder en 1 día