Skip to content

Commit a51caa5

Browse files
fix: default stationary node when inserting a block (#633)
It can be null if the workspace has never taken focus but it's unhelpful to behave as if the user had selected the workspace itself (as via 'w'). Use the same logic as the workspace would use if it had taken focus, which will return the first block. Fixes #629
1 parent ef1faa8 commit a51caa5

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/actions/enter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ export class EnterAction {
185185
Events.setGroup(true);
186186
}
187187

188-
const stationaryNode = FocusableTreeTraverser.findFocusedNode(workspace);
188+
// If the workspace has never had focus default the stationary node.
189+
const stationaryNode =
190+
FocusableTreeTraverser.findFocusedNode(workspace) ??
191+
workspace.getRestoredFocusableNode(null);
189192
const newBlock = this.createNewBlock(workspace);
190193
if (!newBlock) return;
191194
const insertStartPoint = stationaryNode

test/webdriverio/test/insert_test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
testFileLocations,
1616
testSetup,
1717
keyRight,
18+
keyUp,
19+
tabNavigateToToolbox,
1820
} from './test_setup.js';
1921

2022
suite('Insert test', function () {
@@ -45,4 +47,23 @@ suite('Insert test', function () {
4547
await getFocusedBlockType(this.browser),
4648
);
4749
});
50+
51+
test('Insert without having focused the workspace', async function () {
52+
await tabNavigateToToolbox(this.browser);
53+
54+
// Insert 'if' block
55+
await keyRight(this.browser);
56+
// Choose.
57+
await this.browser.keys(Key.Enter);
58+
// Confirm position.
59+
await this.browser.keys(Key.Enter);
60+
61+
// Assert inserted inside first block p5_setup not at top-level.
62+
chai.assert.equal('controls_if', await getFocusedBlockType(this.browser));
63+
await keyUp(this.browser);
64+
chai.assert.equal(
65+
'p5_background_color',
66+
await getFocusedBlockType(this.browser),
67+
);
68+
});
4869
});

test/webdriverio/test/test_setup.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,19 @@ export async function tabNavigateToWorkspace(
424424
tabNavigateForward(browser); // Tab to the workspace itself.
425425
}
426426

427+
/**
428+
* Uses tabs to navigate to the toolbox on the test page (i.e. by going
429+
* through top-level tab stops). Assumes initial load tab position.
430+
*
431+
* @param browser The active WebdriverIO Browser object.
432+
*/
433+
export async function tabNavigateToToolbox(browser: WebdriverIO.Browser) {
434+
// Initial pre-injection focusable div element.
435+
await tabNavigateForward(browser);
436+
// Toolbox.
437+
await tabNavigateForward(browser);
438+
}
439+
427440
/**
428441
* Navigates forward to the test page's next tab stop.
429442
*

0 commit comments

Comments
 (0)