Skip to content

Commit c9465bb

Browse files
authored
fix: dont do keyboard shortcuts when field editors open (#568)
* fix: dont do keyboard shortcuts when field editors open * chore: add tests * chore: simplify copy commands in tests
1 parent 656624a commit c9465bb

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

src/navigation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ export class Navigation {
825825
: workspace.keyboardAccessibilityMode;
826826
return (
827827
!!accessibilityMode &&
828-
this.getState(workspace) !== Constants.STATE.NOWHERE
828+
this.getState(workspace) !== Constants.STATE.NOWHERE &&
829+
!Blockly.getFocusManager().ephemeralFocusTaken()
829830
);
830831
}
831832

test/webdriverio/test/basic_test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,18 @@ suite('Keyboard navigation on Fields', function () {
349349
.expect(await getCurrentFocusedBlockId(this.browser))
350350
.equal('draw_emoji_1');
351351
});
352+
353+
test('Do not navigate while field editor is open', async function () {
354+
// Open a field editor dropdown
355+
await focusOnBlockField(this.browser, 'logic_boolean_1', 'BOOL');
356+
await this.browser.pause(PAUSE_TIME);
357+
await this.browser.keys(Key.Enter);
358+
await this.browser.pause(PAUSE_TIME);
359+
360+
// Try to navigate to a different block
361+
await keyRight(this.browser);
362+
363+
// The same field should still be focused
364+
chai.assert.equal(await getFocusedFieldName(this.browser), 'BOOL');
365+
});
352366
});

test/webdriverio/test/clipboard_test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
ElementWithId,
1616
tabNavigateToWorkspace,
1717
focusOnBlock,
18+
focusOnBlockField,
19+
blockIsPresent,
1820
} from './test_setup.js';
1921
import {Key, KeyAction, PointerAction, WheelAction} from 'webdriverio';
2022

@@ -111,6 +113,22 @@ suite('Clipboard test', function () {
111113
'Blocks on the workspace should not have changed',
112114
);
113115
});
116+
117+
test('Do not cut block while field editor is open', async function () {
118+
// Open a field editor
119+
await focusOnBlockField(this.browser, 'draw_circle_1_color', 'COLOUR');
120+
await this.browser.pause(PAUSE_TIME);
121+
await this.browser.keys(Key.Enter);
122+
await this.browser.pause(PAUSE_TIME);
123+
124+
// Try to cut block while field editor is open
125+
await this.browser.keys([Key.Ctrl, 'x']);
126+
127+
// Block is not deleted
128+
chai.assert.isTrue(
129+
await blockIsPresent(this.browser, 'draw_circle_1_color'),
130+
);
131+
});
114132
});
115133

116134
/**

test/webdriverio/test/delete_test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
PAUSE_TIME,
1717
tabNavigateToWorkspace,
1818
keyRight,
19+
focusOnBlockField,
1920
} from './test_setup.js';
2021
import {Key} from 'webdriverio';
2122

@@ -218,4 +219,18 @@ suite('Deleting Blocks', function () {
218219
'p5_setup_1',
219220
);
220221
});
222+
223+
test('Do not delete block while field editor is open', async function () {
224+
// Open a field editor
225+
await focusOnBlockField(this.browser, 'colour_picker_1', 'COLOUR');
226+
await this.browser.pause(PAUSE_TIME);
227+
await this.browser.keys(Key.Enter);
228+
await this.browser.pause(PAUSE_TIME);
229+
230+
// Try to delete block while field editor is open
231+
await this.browser.keys(Key.Backspace);
232+
233+
// Block is not deleted
234+
chai.assert.isTrue(await blockIsPresent(this.browser, 'colour_picker_1'));
235+
});
221236
});

test/webdriverio/test/keyboard_mode_test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ suite(
8080
// Make sure we're on a copyable block so that copy occurs
8181
await focusOnBlock(this.browser, 'controls_if_2');
8282
await this.browser.pause(PAUSE_TIME);
83-
await this.browser.keys(Key.Ctrl);
84-
await this.browser.keys('c');
85-
await this.browser.keys(Key.Ctrl); // release ctrl key
83+
await this.browser.keys([Key.Ctrl, 'c']);
8684
await this.browser.pause(PAUSE_TIME);
8785

8886
chai.assert.isFalse(await isKeyboardNavigating(this.browser));
@@ -92,9 +90,7 @@ suite(
9290
});
9391

9492
await this.browser.pause(PAUSE_TIME);
95-
await this.browser.keys(Key.Ctrl);
96-
await this.browser.keys('c');
97-
await this.browser.keys(Key.Ctrl); // release ctrl key
93+
await this.browser.keys([Key.Ctrl, 'c']);
9894
await this.browser.pause(PAUSE_TIME);
9995

10096
chai.assert.isTrue(await isKeyboardNavigating(this.browser));

0 commit comments

Comments
 (0)