Skip to content

Commit 8e1c265

Browse files
authored
feat(mover): Report keyboard moves to WorkspaceSvg (#485)
* feat(mover): Report keyboard moves to WorkspaceSvg Call Workspace.prototype.setKeyboardMoveInProgress at the beginning and end of each keyboard-initiated move. * chore(Mover): Remove obsolete WorkspaceSvg monkey patching
1 parent 5378c98 commit 8e1c265

File tree

1 file changed

+3
-42
lines changed

1 file changed

+3
-42
lines changed

src/actions/mover.ts

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ export class Mover {
117117
block: BlockSvg,
118118
insertStartPoint: RenderedConnection | null,
119119
) {
120-
this.patchWorkspace(workspace);
121120
this.patchDragStrategy(block, insertStartPoint);
122121
// Begin dragging block.
123122
const DraggerClass = registry.getClassFromOptions(
@@ -128,6 +127,7 @@ export class Mover {
128127
if (!DraggerClass) throw new Error('no Dragger registered');
129128
const dragger = new DraggerClass(block, workspace);
130129
// Record that a move is in progress and start dragging.
130+
workspace.setKeyboardMoveInProgress(true);
131131
const info = new MoveInfo(block, dragger);
132132
this.moves.set(workspace, info);
133133
// Begin drag.
@@ -158,9 +158,9 @@ export class Mover {
158158
new utils.Coordinate(0, 0),
159159
);
160160

161-
this.unpatchWorkspace(workspace);
162161
this.unpatchDragStrategy(info.block);
163162
this.moves.delete(workspace);
163+
workspace.setKeyboardMoveInProgress(false);
164164
// Delay scroll until after block has finished moving.
165165
setTimeout(() => this.scrollCurrentBlockIntoView(workspace), 0);
166166
// If the block gets reattached, ensure it retains focus.
@@ -206,9 +206,9 @@ export class Mover {
206206
if (newNode) workspace.getCursor()?.setCurNode(newNode);
207207
}
208208

209-
this.unpatchWorkspace(workspace);
210209
this.unpatchDragStrategy(info.block);
211210
this.moves.delete(workspace);
211+
workspace.setKeyboardMoveInProgress(false);
212212
// Delay scroll until after block has finished moving.
213213
setTimeout(() => this.scrollCurrentBlockIntoView(workspace), 0);
214214
// If the block gets reattached, ensure it retains focus.
@@ -261,45 +261,6 @@ export class Mover {
261261
return true;
262262
}
263263

264-
/**
265-
* Monkeypatch over workspace functions to consider keyboard drags as
266-
* well as mouse/pointer drags.
267-
*
268-
* @param workspace The workspace to patch.
269-
*/
270-
private patchWorkspace(workspace: WorkspaceSvg) {
271-
// Keyboard drags are real drags.
272-
this.oldIsDragging = workspace.isDragging;
273-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
274-
(workspace as any).isDragging = () => this.isMoving(workspace);
275-
276-
// Ignore mouse/pointer events during keyboard drags.
277-
this.oldGetGesture = workspace.getGesture;
278-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
279-
(workspace as any).getGesture = (e: PointerEvent) => {
280-
// Normally these would be called from Gesture.doStart.
281-
e.preventDefault();
282-
e.stopPropagation();
283-
return null;
284-
};
285-
}
286-
287-
/**
288-
* Remove monkeypatches on the workspace.
289-
*
290-
* @param workspace The workspace to unpatch.
291-
*/
292-
private unpatchWorkspace(workspace: WorkspaceSvg) {
293-
if (this.oldIsDragging) {
294-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
295-
(workspace as any).isDragging = this.oldIsDragging;
296-
}
297-
if (this.oldGetGesture) {
298-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
299-
(workspace as any).getGesture = this.oldGetGesture;
300-
}
301-
}
302-
303264
/**
304265
* Monkeypatch: replace the block's drag strategy and cache the old value.
305266
*

0 commit comments

Comments
 (0)