Skip to content

Commit 24edccb

Browse files
authored
fix: Don't loop around when navigating (#777)
* fix: Don't loop around when navigating * fix: Fix tests * chore: Remove unused cursor
1 parent 269026b commit 24edccb

File tree

6 files changed

+44
-21
lines changed

6 files changed

+44
-21
lines changed

src/actions/arrow_navigation.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ export class ArrowNavigation {
6666
if (
6767
!this.navigation.defaultWorkspaceCursorPositionIfNeeded(workspace)
6868
) {
69-
workspace.getCursor().in();
69+
const newNode = workspace.getCursor().in();
70+
if (!newNode) {
71+
workspace.getAudioManager().beep(260);
72+
}
7073
}
7174
isHandled = true;
7275
}
@@ -99,7 +102,10 @@ export class ArrowNavigation {
99102
if (
100103
!this.navigation.defaultWorkspaceCursorPositionIfNeeded(workspace)
101104
) {
102-
workspace.getCursor().out();
105+
const newNode = workspace.getCursor().out();
106+
if (!newNode) {
107+
workspace.getAudioManager().beep(260);
108+
}
103109
}
104110
isHandled = true;
105111
}
@@ -165,7 +171,10 @@ export class ArrowNavigation {
165171
workspace,
166172
)
167173
) {
168-
workspace.getCursor().next();
174+
const newNode = workspace.getCursor().next();
175+
if (!newNode) {
176+
workspace.getAudioManager().beep(260);
177+
}
169178
}
170179
isHandled = true;
171180
}
@@ -178,7 +187,10 @@ export class ArrowNavigation {
178187
workspace.targetWorkspace,
179188
)
180189
) {
181-
workspace.getCursor().next();
190+
const newNode = workspace.getCursor().next();
191+
if (!newNode) {
192+
workspace.getAudioManager().beep(260);
193+
}
182194
}
183195
isHandled = true;
184196
}
@@ -228,7 +240,10 @@ export class ArrowNavigation {
228240
'last',
229241
)
230242
) {
231-
workspace.getCursor().prev();
243+
const newNode = workspace.getCursor().prev();
244+
if (!newNode) {
245+
workspace.getAudioManager().beep(260);
246+
}
232247
}
233248
isHandled = true;
234249
}
@@ -242,7 +257,10 @@ export class ArrowNavigation {
242257
'last',
243258
)
244259
) {
245-
workspace.getCursor().prev();
260+
const newNode = workspace.getCursor().prev();
261+
if (!newNode) {
262+
workspace.getAudioManager().beep(260);
263+
}
246264
}
247265
isHandled = true;
248266
}

src/actions/stack_navigation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ export class StackNavigationAction {
6262
}
6363

6464
let nextRoot = navigateStacks(curNodeRoot, delta);
65-
if (!nextRoot) return false;
65+
if (!nextRoot) {
66+
workspace.getAudioManager().beep(260);
67+
return false;
68+
}
6669
if (nextRoot instanceof BlockSvg) {
6770
nextRoot = nextRoot.getRootBlock();
6871
}

src/flyout_cursor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class FlyoutCursor extends Blockly.LineCursor {
2525
*/
2626
constructor(private readonly flyout: Blockly.IFlyout) {
2727
super(flyout.getWorkspace());
28+
this.setNavigationLoops(false);
2829
}
2930

3031
/**

src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ export class KeyboardNavigation {
1717
/** Keyboard navigation controller instance for the workspace. */
1818
private navigationController: NavigationController;
1919

20-
/** Cursor for the main workspace. */
21-
private cursor: Blockly.LineCursor;
22-
2320
/**
2421
* Focus ring in the workspace.
2522
*/
@@ -60,8 +57,6 @@ export class KeyboardNavigation {
6057
this.navigationController.addWorkspace(workspace);
6158
this.navigationController.enable(workspace);
6259

63-
this.cursor = new Blockly.LineCursor(workspace);
64-
6560
// Add the event listener to enable disabled blocks on drag.
6661
workspace.addChangeListener(enableBlocksOnDrag);
6762

@@ -94,6 +89,8 @@ export class KeyboardNavigation {
9489
workspace.getSvgGroup().appendChild(this.workspaceFocusRing);
9590
this.resizeWorkspaceRings();
9691

92+
workspace.getCursor().setNavigationLoops(false);
93+
9794
registerHtmlToast();
9895
}
9996

@@ -307,7 +304,7 @@ export class KeyboardNavigation {
307304
stroke: var(--blockly-active-node-color);
308305
stroke-width: var(--blockly-selection-width);
309306
}
310-
307+
311308
/* The workspace itself is the active node. */
312309
.blocklyKeyboardNavigation
313310
.blocklyBubble.blocklyActiveFocus

test/webdriverio/test/basic_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ suite('Keyboard navigation on Blocks', function () {
4949
await tabNavigateToWorkspace(this.browser);
5050
await this.browser.pause(PAUSE_TIME);
5151

52-
await keyDown(this.browser, 22);
52+
await keyDown(this.browser, 13);
5353

5454
chai
5555
.expect(await getCurrentFocusedBlockId(this.browser))
56-
.equal('controls_if_2');
56+
.equal('controls_repeat_ext_1');
5757
});
5858

5959
test('Down from statement block selects next block across stacks', async function () {

test/webdriverio/test/stack_navigation.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as chai from 'chai';
88
import {
99
getCurrentFocusedBlockId,
1010
getCurrentFocusNodeId,
11+
focusOnWorkspaceComment,
1112
PAUSE_TIME,
1213
tabNavigateToWorkspace,
1314
testFileLocations,
@@ -39,10 +40,10 @@ suite('Stack navigation', function () {
3940
await getCurrentFocusNodeId(this.browser),
4041
);
4142
await sendKeyAndWait(this.browser, 'n');
42-
// Looped around.
43+
// Does not loop around.
4344
chai.assert.equal(
44-
'p5_setup_1',
45-
await getCurrentFocusedBlockId(this.browser),
45+
'workspace_comment_1',
46+
await getCurrentFocusNodeId(this.browser),
4647
);
4748
});
4849

@@ -53,11 +54,14 @@ suite('Stack navigation', function () {
5354
await getCurrentFocusedBlockId(this.browser),
5455
);
5556
await sendKeyAndWait(this.browser, 'b');
56-
// Looped to bottom.
57+
// Does not loop to bottom.
5758
chai.assert.equal(
58-
'workspace_comment_1',
59-
await getCurrentFocusNodeId(this.browser),
59+
'p5_setup_1',
60+
await getCurrentFocusedBlockId(this.browser),
6061
);
62+
63+
await focusOnWorkspaceComment(this.browser, 'workspace_comment_1');
64+
6165
await sendKeyAndWait(this.browser, 'b');
6266
chai.assert.isTrue(
6367
(await getCurrentFocusNodeId(this.browser))?.startsWith(

0 commit comments

Comments
 (0)