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:
adminandClaude Opus 5.5 committed 2026-09-29 06:01:26 +02:00
1 parent d2701b3ec5
commit d7d0a6e7d4
6 files changed
+52 -2

No files matched your search

+35 -1
View File
@@ -8,6 +8,7 @@ import { LANES, scaffoldBehavior } from './lib/scaffold.mjs';
const PLAIN = 'plain hit';
const REPEATING = 'repeating hit';
const TAB = 'tab hit';
const DELAY = 300;
const INTERVAL = 50;
@@ -21,15 +22,18 @@ const repeatGraph = {
repeatInterval: INTERVAL,
}),
node('r-repeat-log', 'Log', 340, 220, { message: REPEATING }),
node('r-tab', 'OnKeyDown', 0, 440, { key: 'Tab' }),
node('r-tab-log', 'Log', 340, 440, { message: TAB }),
],
edges: [
edge('r-e1', 'r-plain', 'exec', 'r-plain-log', 'exec'),
edge('r-e2', 'r-repeat', 'exec', 'r-repeat-log', 'exec'),
edge('r-e3', 'r-tab', 'exec', 'r-tab-log', 'exec'),
],
};
export async function keyRepeat(t) {
const { check, sleep, json, shot, click, holdKey, world, stop, select, typeText } = t;
const { check, sleep, json, shot, click, press, holdKey, world, stop, select, typeText } = t;
/** Both counts out of one read of the world, so the two are always of the same moment. */
const hits = async () => {
const log = (await world()).log;
@@ -125,6 +129,36 @@ export async function keyRepeat(t) {
);
await stop();
// 20f. Tab is a game key like any other while the game has the keyboard. The editor used to move
// its focus on it, so the next key went to a widget and no longer reached the game.
await t.play();
const beforeTab = await hits();
const tabsBefore = (await world()).log.filter((line) => line.includes(TAB)).length;
await press('Tab');
await holdKey('ArrowRight', 120);
await sleep(200);
const afterTab = await hits();
const tabsAfter = (await world()).log.filter((line) => line.includes(TAB)).length;
const focusAfterTab = await json('__gm.focusedRect()');
check(
'Tab reaches the game and leaves the keyboard with it',
tabsAfter === tabsBefore + 1 && afterTab.plain === beforeTab.plain + 1 && focusAfterTab === null,
JSON.stringify({ tabs: tabsAfter - tabsBefore, plain: afterTab.plain - beforeTab.plain, focusAfterTab }),
);
await stop();
// 20g. The key field takes Tab too, or a graph could never be set to it by hand.
await select({ kind: 'node', assetId: 'repeater', nodeId: 'r-plain' });
const keyField = await json(`__gm.inspectorField('Key')`);
await click(keyField.x, keyField.y);
await press('Tab');
const pickedKey = await json(
`__gm.state.project.assets.find((a) => a.id === 'repeater').graph.nodes.find((n) => n.id === 'r-plain').params.key`,
);
check('the key field captures Tab', pickedKey === 'Tab', JSON.stringify({ pickedKey }));
// Selecting the node brought its graph to the front; the steps after this one start in the scene.
await t.showTab('scene');
const left = await rig.remove();
check(
'the step leaves nothing of its own behind',
+1
View File
@@ -38,6 +38,7 @@ export function colourDistance(a, b) {
const KEYS = {
Enter: { key: 'Enter', code: 'Enter', windowsVirtualKeyCode: 13 },
Escape: { key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 },
Tab: { key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 },
Space: { key: ' ', code: 'Space', windowsVirtualKeyCode: 32 },
ArrowLeft: { key: 'ArrowLeft', code: 'ArrowLeft', windowsVirtualKeyCode: 37 },
ArrowUp: { key: 'ArrowUp', code: 'ArrowUp', windowsVirtualKeyCode: 38 },