Skip to content

Commit 49d8c75

Browse files
authored
refactor: Refactor KeyboardShortucts to simplify NavigationController (#61)
* refactor: Include key mappings in shortcuts By adding the key mappings directly to the shortcuts, they will be automatically mapped when the shortcuts are registered. This follows current practice in Blockly core/shortcut_items.ts. * refactor: use Array.prototype.includes instead of .indexOf * refactor: Save original Toolbox.prototype.onShortcut method … and restore it when removeShortcutHandlers is called. * refactor: Put all KeyboardShortcuts in a dictionary object This obviates the need to have separate functions to register each of them, and makes it easy to ensure that we unregister all of them when disposing. This dictionary can be split into separate dictionaries for different modes / sub modes as needed in future.
1 parent ad213f5 commit 49d8c75

File tree

2 files changed

+197
-498
lines changed

2 files changed

+197
-498
lines changed

src/navigation.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export class Navigation {
380380

381381
const curNode = cursor.getCurNode();
382382
const sourceBlock = curNode.getSourceBlock()!;
383-
if (sourceBlock.id === deletedBlockId || ids.indexOf(sourceBlock.id) > -1) {
383+
if (sourceBlock.id === deletedBlockId || ids.includes(sourceBlock.id)) {
384384
cursor.setCurNode(
385385
Blockly.ASTNode.createWorkspaceNode(
386386
workspace,
@@ -457,7 +457,7 @@ export class Navigation {
457457
// cursor to the workspace.
458458
} else if (
459459
block &&
460-
deletedBlock.getChildren(false).indexOf(block as Blockly.BlockSvg) > -1
460+
deletedBlock.getChildren(false).includes(block as Blockly.BlockSvg)
461461
) {
462462
cursor.setCurNode(
463463
Blockly.ASTNode.createWorkspaceNode(
@@ -826,7 +826,7 @@ export class Navigation {
826826
let inferiorConnection;
827827

828828
if (movingBlock.getRootBlock() === destBlock.getRootBlock()) {
829-
if (movingBlock.getDescendants(false).indexOf(destBlock) > -1) {
829+
if (movingBlock.getDescendants(false).includes(destBlock)) {
830830
inferiorConnection = this.getInferiorConnection(destConnection);
831831
if (inferiorConnection) {
832832
inferiorConnection.disconnect();
@@ -1119,7 +1119,7 @@ export class Navigation {
11191119
*/
11201120
enableKeyboardAccessibility(workspace: Blockly.WorkspaceSvg) {
11211121
if (
1122-
this.workspaces.indexOf(workspace) > -1 &&
1122+
this.workspaces.includes(workspace) &&
11231123
!workspace.keyboardAccessibilityMode
11241124
) {
11251125
workspace.keyboardAccessibilityMode = true;
@@ -1135,7 +1135,7 @@ export class Navigation {
11351135
*/
11361136
disableKeyboardAccessibility(workspace: Blockly.WorkspaceSvg) {
11371137
if (
1138-
this.workspaces.indexOf(workspace) > -1 &&
1138+
this.workspaces.includes(workspace) &&
11391139
workspace.keyboardAccessibilityMode
11401140
) {
11411141
workspace.keyboardAccessibilityMode = false;
@@ -1241,7 +1241,8 @@ export class Navigation {
12411241
}
12421242

12431243
/**
1244-
* Pastes the copied block to the marked location.
1244+
* Pastes the copied block to the marked location if possible or
1245+
* onto the workspace otherwise.
12451246
*
12461247
* @param copyData The data to paste into the workspace.
12471248
* @param workspace The workspace to paste the data into.
@@ -1262,9 +1263,10 @@ export class Navigation {
12621263
}
12631264

12641265
/**
1265-
* Inserts the pasted block at the marked location if a compatible connection
1266-
* exists. If no connection has been marked, or there is not a compatible
1267-
* connection then the block is placed on the workspace.
1266+
* Inserts the pasted block at the marked location if a compatible
1267+
* connection exists. If no connection has been marked, or there is
1268+
* not a compatible connection then the block is placed on the
1269+
* workspace.
12681270
*
12691271
* @param workspace The workspace to paste the block on.
12701272
* @param block The block to paste.

0 commit comments

Comments
 (0)