Let Tab reach the game in the Game tab (#261)
The game did get Tab, but the editor moved the keyboard focus to a button at the same time. The next Space then pressed that button instead of reaching the game. The key field of On key down could not capture Tab at all, so an inventory on Tab could not be built. - FocusManager asks tabBelongsElsewhere before it moves the focus. The editor answers yes while the Game tab is in front, so Tab stays with the game as long as no field has the focus. - A widget can claim Tab through takesTab. The key capture button does so while it is capturing, so On key down accepts Tab. - The harness knows the key Tab. Found on the way: - The first version of check 20g left the Behavior tab in front, and module 21 then failed in the chained run. 20g now goes back. Tests: - ./check.sh: 2746 tests, CHECK EXIT 0. - e2e 20 has two new checks: Tab reaches the game and leaves the keyboard with it, the key field captures Tab. Both failed against the old bundle. - GM_STEPS=19,20: all passed, 44 checks. The full local run with all three topics of this push passed with 1543 checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d2701b3ec5
commit
d7d0a6e7d4
6 files changed
+52
-2
No files matched your search
@@ -11,6 +11,8 @@ export class FocusManager {
|
||||
readonly globalHandlers: ((event: KeyboardEvent) => boolean)[] = [];
|
||||
/** Called after focus moved, so a panel can catch up on work it postponed while being typed in. */
|
||||
readonly changeHandlers: (() => void)[] = [];
|
||||
/** With nothing focused, whether Tab is someone else's key (a running game's) rather than a focus move. */
|
||||
tabBelongsElsewhere: () => boolean = () => false;
|
||||
private focusedWidget: Widget | null = null;
|
||||
private readonly onKeyDown = (event: KeyboardEvent) => this.handleKeyDown(event);
|
||||
|
||||
@@ -90,7 +92,8 @@ export class FocusManager {
|
||||
if ((event.target as HTMLElement | null)?.tagName === 'INPUT') return;
|
||||
if (event.key === 'Tab') {
|
||||
event.preventDefault();
|
||||
this.cycle(event.shiftKey);
|
||||
if (this.focusedWidget?.takesTab) this.focusedWidget.onKeyDown(event);
|
||||
else if (this.focusedWidget || !this.tabBelongsElsewhere()) this.cycle(event.shiftKey);
|
||||
return;
|
||||
}
|
||||
this.validate();
|
||||
|
||||
@@ -21,6 +21,10 @@ export abstract class Widget extends Container {
|
||||
/** Whether the widget takes part in Tab cycling. */
|
||||
focusable = false;
|
||||
focused = false;
|
||||
/** While true, a Tab goes to `onKeyDown` instead of moving the focus on. */
|
||||
get takesTab(): boolean {
|
||||
return false;
|
||||
}
|
||||
enabled = true;
|
||||
/** Maintained by `trackHover()`; read in `redraw()` to paint the hover state. */
|
||||
protected hovered = false;
|
||||
|
||||
Reference in new issue
Block a user