@@ -33,65 +33,54 @@ export class WorkspaceMovement {
33
33
this . canCurrentlyEdit = canEdit ;
34
34
}
35
35
36
+ private shortcuts : ShortcutRegistry . KeyboardShortcut [ ] = [
37
+ /** Move the cursor on the workspace to the left. */
38
+ {
39
+ name : Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_LEFT ,
40
+ preconditionFn : ( workspace ) => this . canCurrentlyEdit ( workspace ) ,
41
+ callback : ( workspace ) => this . moveWSCursor ( workspace , - 1 , 0 ) ,
42
+ keyCodes : [ createSerializedKey ( KeyCodes . A , [ KeyCodes . SHIFT ] ) ] ,
43
+ } ,
44
+ /** Move the cursor on the workspace to the right. */
45
+ {
46
+ name : Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_RIGHT ,
47
+ preconditionFn : ( workspace ) => this . canCurrentlyEdit ( workspace ) ,
48
+ callback : ( workspace ) => this . moveWSCursor ( workspace , 1 , 0 ) ,
49
+ keyCodes : [ createSerializedKey ( KeyCodes . D , [ KeyCodes . SHIFT ] ) ] ,
50
+ } ,
51
+ /** Move the cursor on the workspace up. */
52
+ {
53
+ name : Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_UP ,
54
+ preconditionFn : ( workspace ) => this . canCurrentlyEdit ( workspace ) ,
55
+ callback : ( workspace ) => this . moveWSCursor ( workspace , 0 , - 1 ) ,
56
+ keyCodes : [ createSerializedKey ( KeyCodes . W , [ KeyCodes . SHIFT ] ) ] ,
57
+ } ,
58
+
59
+ /** Move the cursor on the workspace down. */
60
+ {
61
+ name : Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_DOWN ,
62
+ preconditionFn : ( workspace ) => this . canCurrentlyEdit ( workspace ) ,
63
+ callback : ( workspace ) => this . moveWSCursor ( workspace , 0 , 1 ) ,
64
+ keyCodes : [ createSerializedKey ( KeyCodes . S , [ KeyCodes . SHIFT ] ) ] ,
65
+ } ,
66
+ ] ;
67
+
36
68
/**
37
- * Install these actions as both keyboard shortcuts and context menu items .
69
+ * Install the shortcuts.
38
70
*/
39
71
install ( ) {
40
- const shortcutList : {
41
- [ name : string ] : ShortcutRegistry . KeyboardShortcut ;
42
- } = {
43
- /** Move the cursor on the workspace to the left. */
44
- wsMoveLeft : {
45
- name : Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_LEFT ,
46
- preconditionFn : ( workspace ) => this . canCurrentlyEdit ( workspace ) ,
47
- callback : ( workspace ) => this . moveWSCursor ( workspace , - 1 , 0 ) ,
48
- keyCodes : [ createSerializedKey ( KeyCodes . A , [ KeyCodes . SHIFT ] ) ] ,
49
- } ,
50
- /** Move the cursor on the workspace to the right. */
51
- wsMoveRight : {
52
- name : Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_RIGHT ,
53
- preconditionFn : ( workspace ) => this . canCurrentlyEdit ( workspace ) ,
54
- callback : ( workspace ) => this . moveWSCursor ( workspace , 1 , 0 ) ,
55
- keyCodes : [ createSerializedKey ( KeyCodes . D , [ KeyCodes . SHIFT ] ) ] ,
56
- } ,
57
-
58
- /** Move the cursor on the workspace up. */
59
- wsMoveUp : {
60
- name : Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_UP ,
61
- preconditionFn : ( workspace ) => this . canCurrentlyEdit ( workspace ) ,
62
- callback : ( workspace ) => this . moveWSCursor ( workspace , 0 , - 1 ) ,
63
- keyCodes : [ createSerializedKey ( KeyCodes . W , [ KeyCodes . SHIFT ] ) ] ,
64
- } ,
65
-
66
- /** Move the cursor on the workspace down. */
67
- wsMoveDown : {
68
- name : Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_DOWN ,
69
- preconditionFn : ( workspace ) => this . canCurrentlyEdit ( workspace ) ,
70
- callback : ( workspace ) => this . moveWSCursor ( workspace , 0 , 1 ) ,
71
- keyCodes : [ createSerializedKey ( KeyCodes . S , [ KeyCodes . SHIFT ] ) ] ,
72
- } ,
73
- } ;
74
- for ( const shortcut of Object . values ( shortcutList ) ) {
72
+ for ( const shortcut of this . shortcuts ) {
75
73
ShortcutRegistry . registry . register ( shortcut ) ;
76
74
}
77
75
}
78
76
79
77
/**
80
- * Uninstall these actions .
78
+ * Uninstall the shortcuts .
81
79
*/
82
80
uninstall ( ) {
83
- ShortcutRegistry . registry . unregister (
84
- Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_LEFT ,
85
- ) ;
86
- ShortcutRegistry . registry . unregister (
87
- Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_RIGHT ,
88
- ) ;
89
- ShortcutRegistry . registry . unregister (
90
- Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_UP ,
91
- ) ;
92
- ShortcutRegistry . registry . unregister (
93
- Constants . SHORTCUT_NAMES . MOVE_WS_CURSOR_DOWN ,
94
- ) ;
81
+ for ( const shortcut of this . shortcuts ) {
82
+ ShortcutRegistry . registry . unregister ( shortcut . name ) ;
83
+ }
95
84
}
96
85
97
86
/**
@@ -109,14 +98,9 @@ export class WorkspaceMovement {
109
98
yDirection : number ,
110
99
) : boolean {
111
100
const cursor = workspace . getCursor ( ) ;
112
- if ( ! cursor ) {
113
- return false ;
114
- }
115
- const curNode = cursor . getCurNode ( ) ;
116
-
117
- if ( curNode . getType ( ) !== ASTNode . types . WORKSPACE ) {
118
- return false ;
119
- }
101
+ if ( ! cursor ) return false ;
102
+ const curNode = cursor ?. getCurNode ( ) ;
103
+ if ( curNode . getType ( ) !== ASTNode . types . WORKSPACE ) return false ;
120
104
121
105
const wsCoord = curNode . getWsCoordinate ( ) ;
122
106
const newX = xDirection * this . WS_MOVE_DISTANCE + wsCoord . x ;
0 commit comments