Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/actions/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export class DeleteAction {
*/
private oldContextMenuItem: ContextMenuRegistry.RegistryItem | null = null;

/**
* Saved delete shortcut, which is re-registered when this action
* is uninstalled.
*/
private oldDeleteShortcut: ShortcutRegistry.KeyboardShortcut | null = null;

/**
* Registration name for the keyboard shortcut.
*/
Expand All @@ -53,19 +59,30 @@ export class DeleteAction {
ContextMenuRegistry.registry.register(this.oldContextMenuItem);
}
ShortcutRegistry.registry.unregister(this.deleteShortcutName);
if (this.oldDeleteShortcut) {
ShortcutRegistry.registry.register(this.oldDeleteShortcut);
}
}

/**
* Create and register the keyboard shortcut for this action.
*/
private registerShortcut() {
this.oldDeleteShortcut = ShortcutRegistry.registry.getRegistry()['delete'];

if (!this.oldDeleteShortcut) return;

// Unregister the original shortcut.
ShortcutRegistry.registry.unregister(this.oldDeleteShortcut.name);

const deleteShortcut: ShortcutRegistry.KeyboardShortcut = {
name: this.deleteShortcutName,
preconditionFn: this.deletePrecondition.bind(this),
callback: this.deleteCallback.bind(this),
keyCodes: [KeyCodes.DELETE, KeyCodes.BACKSPACE],
allowCollision: true,
};

ShortcutRegistry.registry.register(deleteShortcut);
}

Expand Down Expand Up @@ -139,6 +156,7 @@ export class DeleteAction {
private deletePrecondition(workspace: WorkspaceSvg) {
const sourceBlock = workspace.getCursor()?.getCurNode()?.getSourceBlock();
return (
!workspace.isDragging() &&
this.navigation.canCurrentlyEdit(workspace) &&
!!sourceBlock?.isDeletable()
);
Expand Down
Loading