fix(gui): el foco de teclado cae en el editor de prompt al arrancar (antes: botón de cabecera) - #10
Merged
Merged
Conversation
User-reported: opening the app and typing did nothing — 'no me deja escribir'. Root cause chain, established empirically with focus polling under a real event loop: 1. Qt assigns initial focus when the window is ACTIVATED, not at show(); the winner is the first focusable child — the header 'Activar modo extremo' toggle button — so keystrokes go nowhere visible. 2. The assignment is queued AFTER the activation event, so claims made in __init__ or showEvent (and even singleShot(0) from changeEvent) are overwritten by it. 3. The app may open directly in EXTREME mode: settings restore brings back the last-used mode (_collect_settings persists 'mode'), and the original fix only covered the simple-mode editor. Fix: a one-shot 20 ms watcher armed on the first WindowActivationChange waits until Qt's initial assignment has actually landed (focus reaches the toggle button — that landing is the signal), then claims focus for the CURRENT mode's editor (simple_prompt_edit or prompt_edit). It never fights the user: if focus lands on any other real target it stops without claiming, and a 100-tick cap bounds it. Verified by execution: focus polling shows QPushButton before, editor after; TestInitialFocus waits on the condition (QTest.qWait loop) and passes for the settings-restored extreme mode. Suite: 312 passed + 10 subtests, ruff clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
«No me deja escribir» (reporte del usuario al abrir la app)
Causa raíz (establecida por sondeo de foco bajo bucle real de eventos):
show()), no en el constructor: el ganador es el primer hijo enfocable — el botón «Activar modo extremo» de la cabecera. Las teclas no van a ningún sitio visible.__init__,showEventosingleShot(0)desdechangeEventpierde la carrera (las tres variantes fallaron empíricamente)._restore_settingspuede abrir directamente modo extremo (persiste el último modo usado) y el fix inicial solo cubría el editor simple.Fix: vigía de 20 ms armado en la primera
WindowActivationChange— espera a que la asignación de Qt aterrice (foco = botón de cabecera; esa señal es la condición) y entonces reclama el foco para el editor del modo activo (simple_prompt_edit/prompt_edit). No pelea con el usuario: si el foco cae en otro objetivo real, para sin reclamar; tope de 100 ticks.Verificado por ejecución: sondeo botón→editor;
TestInitialFocusespera la condición conQTest.qWaity pasa con el modo extremo restaurado por settings. Suite: 312 passed + 10 subtests, ruff limpio.