Skip to content

Commit e2ebdf0

Browse files
authored
feat: Add cleanup shortcut (#53)
Add 'c' as shortcut keybinding to run workspace.cleanUp().
1 parent 4371d28 commit e2ebdf0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/navigation_controller.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,29 @@ export class NavigationController {
10811081
ShortcutRegistry.registry.addKeyMapping(ctrlShiftI, shortcut.name);
10821082
}
10831083

1084+
/**
1085+
* Register a shortcut to clean up the workspace.
1086+
*/
1087+
registerCleanup() {
1088+
const cleanupShortcut: Blockly.ShortcutRegistry.KeyboardShortcut = {
1089+
name: 'Clean up workspace',
1090+
preconditionFn: (workspace) => {
1091+
return workspace.getTopBlocks(false).length > 0;
1092+
},
1093+
callback: (workspace) => {
1094+
workspace.cleanUp();
1095+
this.announcer.setText('clean up');
1096+
return true;
1097+
},
1098+
};
1099+
1100+
ShortcutRegistry.registry.register(cleanupShortcut);
1101+
ShortcutRegistry.registry.addKeyMapping(
1102+
BlocklyUtils.KeyCodes.C,
1103+
cleanupShortcut.name,
1104+
);
1105+
}
1106+
10841107
/**
10851108
* Registers all default keyboard shortcut items for keyboard navigation. This
10861109
* should be called once per instance of KeyboardShortcutRegistry.
@@ -1115,6 +1138,8 @@ export class NavigationController {
11151138
this.registerListShortcuts();
11161139
this.registerContextIn();
11171140
this.registerContextOut();
1141+
1142+
this.registerCleanup();
11181143
}
11191144

11201145
/**

0 commit comments

Comments
 (0)