From 389de9d76a511730edd20ffaee19403c80707b82 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 14 Mar 2025 14:25:04 -0700 Subject: [PATCH] feat: W to move the cursor to the workspace --- src/actions/ws_movement.ts | 28 +++++++++++++++++++++++++++- src/constants.ts | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/actions/ws_movement.ts b/src/actions/ws_movement.ts index 6286d6a2..436c1186 100644 --- a/src/actions/ws_movement.ts +++ b/src/actions/ws_movement.ts @@ -55,7 +55,7 @@ export class WorkspaceMovement { callback: (workspace) => this.moveWSCursor(workspace, 0, -1), keyCodes: [createSerializedKey(KeyCodes.W, [KeyCodes.SHIFT])], }, - + /** Move the cursor on the workspace down. */ { name: Constants.SHORTCUT_NAMES.MOVE_WS_CURSOR_DOWN, @@ -63,6 +63,14 @@ export class WorkspaceMovement { callback: (workspace) => this.moveWSCursor(workspace, 0, 1), keyCodes: [createSerializedKey(KeyCodes.S, [KeyCodes.SHIFT])], }, + + /** Move the cursor to the workspace. */ + { + name: Constants.SHORTCUT_NAMES.CREATE_WS_CURSOR, + preconditionFn: (workspace) => this.canCurrentlyEdit(workspace), + callback: (workspace) => this.createWSCursor(workspace), + keyCodes: [KeyCodes.W], + }, ]; /** @@ -114,4 +122,22 @@ export class WorkspaceMovement { ); return true; } + + /** + * Moves the cursor to the workspace near the origin. + * + * @param workspace The workspace the cursor is on. + */ + createWSCursor(workspace: WorkspaceSvg) { + const workspaceNode = ASTNode.createWorkspaceNode( + workspace, + new BlocklyUtils.Coordinate(10, 10), + ); + const cursor = workspace.getCursor(); + + if (!cursor || !workspaceNode) return false; + + cursor.setCurNode(workspaceNode); + return true; + } } diff --git a/src/constants.ts b/src/constants.ts index 98f6aa17..4fb5cedd 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -43,6 +43,7 @@ export enum SHORTCUT_NAMES { MOVE_WS_CURSOR_DOWN = 'workspace_down', MOVE_WS_CURSOR_LEFT = 'workspace_left', MOVE_WS_CURSOR_RIGHT = 'workspace_right', + CREATE_WS_CURSOR = 'to_workspace', /* eslint-enable @typescript-eslint/naming-convention */ LIST_SHORTCUTS = 'list_shortcuts', CLEAN_UP = 'clean_up_workspace',