From 6155b0e625ab5d71a01ae0e094b347877451b96e Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Tue, 28 Jan 2025 16:49:56 +0000 Subject: [PATCH] fix: copy/delete shortcuts must bind extracted functions (#176) Otherwise delete and copy shortcuts error when accessing fields on `this`. --- src/navigation_controller.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/navigation_controller.ts b/src/navigation_controller.ts index fe2a2f2..e23d7a9 100644 --- a/src/navigation_controller.ts +++ b/src/navigation_controller.ts @@ -651,8 +651,8 @@ export class NavigationController { /** Copy the block the cursor is currently on. */ copy: { name: Constants.SHORTCUT_NAMES.COPY, - preconditionFn: this.blockCopyPreconditionFn, - callback: this.blockCopyCallbackFn, + preconditionFn: this.blockCopyPreconditionFn.bind(this), + callback: this.blockCopyCallbackFn.bind(this), keyCodes: [ createSerializedKey(KeyCodes.C, [KeyCodes.CTRL]), createSerializedKey(KeyCodes.C, [KeyCodes.ALT]), @@ -725,8 +725,8 @@ export class NavigationController { /** Keyboard shortcut to delete the block the cursor is currently on. */ delete: { name: Constants.SHORTCUT_NAMES.DELETE, - preconditionFn: this.deletePreconditionFn, - callback: this.deleteCallbackFn, + preconditionFn: this.deletePreconditionFn.bind(this), + callback: this.deleteCallbackFn.bind(this), keyCodes: [KeyCodes.DELETE, KeyCodes.BACKSPACE], allowCollision: true, },