Skip to content

Commit 6dd03e9

Browse files
feat: add loopback when finding a valid node during a keyboard drag (#409)
* fix: add looping for finding the next/previous node during movement * chore: fix lint in undo_redo.ts * feat: use core looping feature
1 parent 053faf2 commit 6dd03e9

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

src/actions/undo_redo.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {
8-
ShortcutRegistry,
9-
utils as BlocklyUtils,
10-
ShortcutItems,
11-
WorkspaceSvg,
12-
} from 'blockly/core';
13-
14-
import * as Constants from '../constants';
15-
import type {Navigation} from '../navigation';
16-
17-
const KeyCodes = BlocklyUtils.KeyCodes;
7+
import {ShortcutRegistry, ShortcutItems, WorkspaceSvg} from 'blockly/core';
188

199
/**
2010
* Class for registering a shortcut for undo/redo actions.

src/keyboard_drag_strategy.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,20 @@ export class KeyboardDragStrategy extends dragging.BlockDragStrategy {
144144
const cursor = draggingBlock.workspace.getCursor() as LineCursor;
145145
if (!cursor) return null;
146146

147+
// Helper function for traversal.
148+
function isConnection(node: ASTNode | null): boolean {
149+
return !!node && node.isConnection();
150+
}
151+
147152
const connectionChecker = draggingBlock.workspace.connectionChecker;
148153
let candidateConnection: ConnectionCandidate | null = null;
149154
let potential: ASTNode | null = this.searchNode;
150155
const dir = this.currentDragDirection;
151156
while (potential && !candidateConnection) {
152157
if (dir === Direction.Up || dir === Direction.Left) {
153-
potential = cursor.getPreviousNode(potential, (node) => {
154-
// @ts-expect-error isConnectionType is private.
155-
return node && ASTNode.isConnectionType(node.getType());
156-
});
158+
potential = cursor.getPreviousNode(potential, isConnection, true);
157159
} else if (dir === Direction.Down || dir === Direction.Right) {
158-
potential = cursor.getNextNode(potential, (node) => {
159-
// @ts-expect-error isConnectionType is private.
160-
return node && ASTNode.isConnectionType(node.getType());
161-
});
160+
potential = cursor.getNextNode(potential, isConnection, true);
162161
}
163162

164163
localConns.forEach((conn: RenderedConnection) => {

0 commit comments

Comments
 (0)