Skip to content

Commit 72ab1bc

Browse files
feat: W to move the cursor to the workspace (#319)
1 parent 397db77 commit 72ab1bc

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/actions/ws_movement.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,22 @@ export class WorkspaceMovement {
5555
callback: (workspace) => this.moveWSCursor(workspace, 0, -1),
5656
keyCodes: [createSerializedKey(KeyCodes.W, [KeyCodes.SHIFT])],
5757
},
58-
58+
5959
/** Move the cursor on the workspace down. */
6060
{
6161
name: Constants.SHORTCUT_NAMES.MOVE_WS_CURSOR_DOWN,
6262
preconditionFn: (workspace) => this.canCurrentlyEdit(workspace),
6363
callback: (workspace) => this.moveWSCursor(workspace, 0, 1),
6464
keyCodes: [createSerializedKey(KeyCodes.S, [KeyCodes.SHIFT])],
6565
},
66+
67+
/** Move the cursor to the workspace. */
68+
{
69+
name: Constants.SHORTCUT_NAMES.CREATE_WS_CURSOR,
70+
preconditionFn: (workspace) => this.canCurrentlyEdit(workspace),
71+
callback: (workspace) => this.createWSCursor(workspace),
72+
keyCodes: [KeyCodes.W],
73+
},
6674
];
6775

6876
/**
@@ -114,4 +122,22 @@ export class WorkspaceMovement {
114122
);
115123
return true;
116124
}
125+
126+
/**
127+
* Moves the cursor to the workspace near the origin.
128+
*
129+
* @param workspace The workspace the cursor is on.
130+
*/
131+
createWSCursor(workspace: WorkspaceSvg) {
132+
const workspaceNode = ASTNode.createWorkspaceNode(
133+
workspace,
134+
new BlocklyUtils.Coordinate(10, 10),
135+
);
136+
const cursor = workspace.getCursor();
137+
138+
if (!cursor || !workspaceNode) return false;
139+
140+
cursor.setCurNode(workspaceNode);
141+
return true;
142+
}
117143
}

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export enum SHORTCUT_NAMES {
4343
MOVE_WS_CURSOR_DOWN = 'workspace_down',
4444
MOVE_WS_CURSOR_LEFT = 'workspace_left',
4545
MOVE_WS_CURSOR_RIGHT = 'workspace_right',
46+
CREATE_WS_CURSOR = 'to_workspace',
4647
/* eslint-enable @typescript-eslint/naming-convention */
4748
LIST_SHORTCUTS = 'list_shortcuts',
4849
CLEAN_UP = 'clean_up_workspace',

0 commit comments

Comments
 (0)