Skip to content

Commit 86f7795

Browse files
committed
chore: Fix post-rebase.
1 parent 04e46d2 commit 86f7795

File tree

1 file changed

+153
-140
lines changed

1 file changed

+153
-140
lines changed

src/actions/move.ts

Lines changed: 153 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -27,166 +27,179 @@ const createSerializedKey = ShortcutRegistry.registry.createSerializedKey.bind(
2727
export class MoveActions {
2828
constructor(private mover: Mover) {}
2929

30-
private shortcuts: ShortcutRegistry.KeyboardShortcut[] = [
31-
// Begin and end move.
32-
{
33-
name: Msg['START_MOVE'],
34-
preconditionFn: (workspace) => {
35-
const startBlock = this.getCurrentBlock(workspace);
36-
return !!startBlock && this.mover.canMove(workspace, startBlock);
30+
private shortcutNames: string[] = [];
31+
private menuItemNames: string[] = [];
32+
33+
private registerShortcuts() {
34+
const shortcuts: ShortcutRegistry.KeyboardShortcut[] = [
35+
// Begin and end move.
36+
{
37+
name: Msg['START_MOVE'],
38+
preconditionFn: (workspace) => {
39+
const startBlock = this.getCurrentBlock(workspace);
40+
return !!startBlock && this.mover.canMove(workspace, startBlock);
41+
},
42+
callback: (workspace) => {
43+
const startBlock = this.getCurrentBlock(workspace);
44+
return (
45+
!!startBlock && this.mover.startMove(workspace, startBlock, null)
46+
);
47+
},
48+
keyCodes: [KeyCodes.M],
3749
},
38-
callback: (workspace) => {
39-
const startBlock = this.getCurrentBlock(workspace);
40-
return (
41-
!!startBlock && this.mover.startMove(workspace, startBlock, null)
42-
);
50+
{
51+
name: Msg['FINISH_MOVE'],
52+
preconditionFn: (workspace) => this.mover.isMoving(workspace),
53+
callback: (workspace) => this.mover.finishMove(workspace),
54+
keyCodes: [KeyCodes.ENTER, KeyCodes.SPACE],
55+
allowCollision: true,
56+
},
57+
{
58+
name: Msg['ABORT_MOVE'],
59+
preconditionFn: (workspace) => this.mover.isMoving(workspace),
60+
callback: (workspace) => this.mover.abortMove(workspace),
61+
keyCodes: [KeyCodes.ESC],
62+
allowCollision: true,
4363
},
44-
keyCodes: [KeyCodes.M],
45-
},
46-
{
47-
name: Msg['FINISH_MOVE'],
48-
preconditionFn: (workspace) => this.mover.isMoving(workspace),
49-
callback: (workspace) => this.mover.finishMove(workspace),
50-
keyCodes: [KeyCodes.ENTER, KeyCodes.SPACE],
51-
allowCollision: true,
52-
},
53-
{
54-
name: Msg['ABORT_MOVE'],
55-
preconditionFn: (workspace) => this.mover.isMoving(workspace),
56-
callback: (workspace) => this.mover.abortMove(workspace),
57-
keyCodes: [KeyCodes.ESC],
58-
allowCollision: true,
59-
},
6064

61-
// Constrained moves.
62-
{
63-
name: Msg['MOVE_LEFT_CONSTRAINED'],
64-
preconditionFn: (workspace) => this.mover.isMoving(workspace),
65-
callback: (workspace) =>
66-
this.mover.moveConstrained(workspace, Direction.Left),
67-
keyCodes: [KeyCodes.LEFT],
68-
allowCollision: true,
69-
},
70-
{
71-
name: Msg['MOVE_RIGHT_CONSTRAINED'],
72-
preconditionFn: (workspace) => this.mover.isMoving(workspace),
73-
callback: (workspace) =>
74-
this.mover.moveConstrained(workspace, Direction.Right),
75-
keyCodes: [KeyCodes.RIGHT],
76-
allowCollision: true,
77-
},
78-
{
79-
name: Msg['MOVE_UP_CONSTRAINED'],
80-
preconditionFn: (workspace) => this.mover.isMoving(workspace),
81-
callback: (workspace) =>
82-
this.mover.moveConstrained(workspace, Direction.Up),
83-
keyCodes: [KeyCodes.UP],
84-
allowCollision: true,
85-
},
86-
{
87-
name: Msg['MOVE_DOWN_CONSTRAINED'],
88-
preconditionFn: (workspace) => this.mover.isMoving(workspace),
89-
callback: (workspace) =>
90-
this.mover.moveConstrained(workspace, Direction.Down),
91-
keyCodes: [KeyCodes.DOWN],
92-
allowCollision: true,
93-
},
65+
// Constrained moves.
66+
{
67+
name: Msg['MOVE_LEFT_CONSTRAINED'],
68+
preconditionFn: (workspace) => this.mover.isMoving(workspace),
69+
callback: (workspace) =>
70+
this.mover.moveConstrained(workspace, Direction.Left),
71+
keyCodes: [KeyCodes.LEFT],
72+
allowCollision: true,
73+
},
74+
{
75+
name: Msg['MOVE_RIGHT_CONSTRAINED'],
76+
preconditionFn: (workspace) => this.mover.isMoving(workspace),
77+
callback: (workspace) =>
78+
this.mover.moveConstrained(workspace, Direction.Right),
79+
keyCodes: [KeyCodes.RIGHT],
80+
allowCollision: true,
81+
},
82+
{
83+
name: Msg['MOVE_UP_CONSTRAINED'],
84+
preconditionFn: (workspace) => this.mover.isMoving(workspace),
85+
callback: (workspace) =>
86+
this.mover.moveConstrained(workspace, Direction.Up),
87+
keyCodes: [KeyCodes.UP],
88+
allowCollision: true,
89+
},
90+
{
91+
name: Msg['MOVE_DOWN_CONSTRAINED'],
92+
preconditionFn: (workspace) => this.mover.isMoving(workspace),
93+
callback: (workspace) =>
94+
this.mover.moveConstrained(workspace, Direction.Down),
95+
keyCodes: [KeyCodes.DOWN],
96+
allowCollision: true,
97+
},
9498

95-
// Unconstrained moves.
96-
{
97-
name: Msg['MOVE_LEFT_UNCONSTRAINED'],
98-
preconditionFn: (workspace) => this.mover.isMoving(workspace),
99-
callback: (workspace) =>
100-
this.mover.moveUnconstrained(workspace, Direction.Left),
101-
keyCodes: [
102-
createSerializedKey(KeyCodes.LEFT, [KeyCodes.ALT]),
103-
createSerializedKey(KeyCodes.LEFT, [KeyCodes.CTRL]),
104-
],
105-
},
106-
{
107-
name: Msg['MOVE_RIGHT_UNCONSTRAINED'],
108-
preconditionFn: (workspace) => this.mover.isMoving(workspace),
109-
callback: (workspace) =>
110-
this.mover.moveUnconstrained(workspace, Direction.Right),
111-
keyCodes: [
112-
createSerializedKey(KeyCodes.RIGHT, [KeyCodes.ALT]),
113-
createSerializedKey(KeyCodes.RIGHT, [KeyCodes.CTRL]),
114-
],
115-
},
116-
{
117-
name: Msg['MOVE_UP_UNCONSTRAINED'],
118-
preconditionFn: (workspace) => this.mover.isMoving(workspace),
119-
callback: (workspace) =>
120-
this.mover.moveUnconstrained(workspace, Direction.Up),
121-
keyCodes: [
122-
createSerializedKey(KeyCodes.UP, [KeyCodes.ALT]),
123-
createSerializedKey(KeyCodes.UP, [KeyCodes.CTRL]),
124-
],
125-
},
126-
{
127-
name: Msg['MOVE_DOWN_UNCONSTRAINED'],
128-
preconditionFn: (workspace) => this.mover.isMoving(workspace),
129-
callback: (workspace) =>
130-
this.mover.moveUnconstrained(workspace, Direction.Down),
131-
keyCodes: [
132-
createSerializedKey(KeyCodes.DOWN, [KeyCodes.ALT]),
133-
createSerializedKey(KeyCodes.DOWN, [KeyCodes.CTRL]),
134-
],
135-
},
136-
];
99+
// Unconstrained moves.
100+
{
101+
name: Msg['MOVE_LEFT_UNCONSTRAINED'],
102+
preconditionFn: (workspace) => this.mover.isMoving(workspace),
103+
callback: (workspace) =>
104+
this.mover.moveUnconstrained(workspace, Direction.Left),
105+
keyCodes: [
106+
createSerializedKey(KeyCodes.LEFT, [KeyCodes.ALT]),
107+
createSerializedKey(KeyCodes.LEFT, [KeyCodes.CTRL]),
108+
],
109+
},
110+
{
111+
name: Msg['MOVE_RIGHT_UNCONSTRAINED'],
112+
preconditionFn: (workspace) => this.mover.isMoving(workspace),
113+
callback: (workspace) =>
114+
this.mover.moveUnconstrained(workspace, Direction.Right),
115+
keyCodes: [
116+
createSerializedKey(KeyCodes.RIGHT, [KeyCodes.ALT]),
117+
createSerializedKey(KeyCodes.RIGHT, [KeyCodes.CTRL]),
118+
],
119+
},
120+
{
121+
name: Msg['MOVE_UP_UNCONSTRAINED'],
122+
preconditionFn: (workspace) => this.mover.isMoving(workspace),
123+
callback: (workspace) =>
124+
this.mover.moveUnconstrained(workspace, Direction.Up),
125+
keyCodes: [
126+
createSerializedKey(KeyCodes.UP, [KeyCodes.ALT]),
127+
createSerializedKey(KeyCodes.UP, [KeyCodes.CTRL]),
128+
],
129+
},
130+
{
131+
name: Msg['MOVE_DOWN_UNCONSTRAINED'],
132+
preconditionFn: (workspace) => this.mover.isMoving(workspace),
133+
callback: (workspace) =>
134+
this.mover.moveUnconstrained(workspace, Direction.Down),
135+
keyCodes: [
136+
createSerializedKey(KeyCodes.DOWN, [KeyCodes.ALT]),
137+
createSerializedKey(KeyCodes.DOWN, [KeyCodes.CTRL]),
138+
],
139+
},
140+
];
137141

138-
menuItems: ContextMenuRegistry.RegistryItem[] = [
139-
{
140-
displayText: Msg['MOVE_BLOCK'].replace(
141-
'%1',
142-
getShortActionShortcut(Msg['START_MOVE']),
143-
),
144-
preconditionFn: (scope, menuOpenEvent) => {
145-
const workspace = scope.block?.workspace as WorkspaceSvg | null;
146-
if (!workspace || menuOpenEvent instanceof PointerEvent)
147-
return 'hidden';
142+
for (const shortcut of shortcuts) {
143+
ShortcutRegistry.registry.register(shortcut);
144+
this.shortcutNames.push(shortcut.name);
145+
}
146+
}
148147

149-
const startBlock = this.getCurrentBlock(workspace);
150-
return !!startBlock && this.mover.canMove(workspace, startBlock)
151-
? 'enabled'
152-
: 'disabled';
153-
},
154-
callback: (scope) => {
155-
const workspace = scope.block?.workspace as WorkspaceSvg | null;
156-
if (!workspace) return false;
157-
const startBlock = this.getCurrentBlock(workspace);
158-
return (
159-
!!startBlock && this.mover.startMove(workspace, startBlock, null)
160-
);
148+
private registerMenuItems() {
149+
const menuItems: ContextMenuRegistry.RegistryItem[] = [
150+
{
151+
displayText: Msg['MOVE_BLOCK'].replace(
152+
'%1',
153+
getShortActionShortcut(Msg['START_MOVE']),
154+
),
155+
preconditionFn: (scope, menuOpenEvent) => {
156+
const workspace = scope.block?.workspace as WorkspaceSvg | null;
157+
if (!workspace || menuOpenEvent instanceof PointerEvent)
158+
return 'hidden';
159+
160+
const startBlock = this.getCurrentBlock(workspace);
161+
return !!startBlock && this.mover.canMove(workspace, startBlock)
162+
? 'enabled'
163+
: 'disabled';
164+
},
165+
callback: (scope) => {
166+
const workspace = scope.block?.workspace as WorkspaceSvg | null;
167+
if (!workspace) return false;
168+
const startBlock = this.getCurrentBlock(workspace);
169+
return (
170+
!!startBlock && this.mover.startMove(workspace, startBlock, null)
171+
);
172+
},
173+
scopeType: ContextMenuRegistry.ScopeType.BLOCK,
174+
id: 'move',
175+
weight: 8.5,
161176
},
162-
scopeType: ContextMenuRegistry.ScopeType.BLOCK,
163-
id: 'move',
164-
weight: 8.5,
165-
},
166-
];
177+
];
178+
179+
for (const menuItem of menuItems) {
180+
ContextMenuRegistry.registry.register(menuItem);
181+
this.menuItemNames.push(menuItem.id);
182+
}
183+
}
167184

168185
/**
169186
* Install the actions as both keyboard shortcuts and (where
170187
* applicable) context menu items.
171188
*/
172189
install() {
173-
for (const shortcut of this.shortcuts) {
174-
ShortcutRegistry.registry.register(shortcut);
175-
}
176-
for (const menuItem of this.menuItems) {
177-
ContextMenuRegistry.registry.register(menuItem);
178-
}
190+
this.registerShortcuts();
191+
this.registerMenuItems();
179192
}
180193

181194
/**
182195
* Uninstall these actions.
183196
*/
184197
uninstall() {
185-
for (const shortcut of this.shortcuts) {
186-
ShortcutRegistry.registry.unregister(shortcut.name);
198+
for (const shortcut of this.shortcutNames) {
199+
ShortcutRegistry.registry.unregister(shortcut);
187200
}
188-
for (const menuItem of this.menuItems) {
189-
ContextMenuRegistry.registry.unregister(menuItem.id);
201+
for (const menuItem of this.menuItemNames) {
202+
ContextMenuRegistry.registry.unregister(menuItem);
190203
}
191204
}
192205

0 commit comments

Comments
 (0)