Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 3 additions & 42 deletions src/actions/mover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export class Mover {
block: BlockSvg,
insertStartPoint: RenderedConnection | null,
) {
this.patchWorkspace(workspace);
this.patchDragStrategy(block, insertStartPoint);
// Begin dragging block.
const DraggerClass = registry.getClassFromOptions(
Expand All @@ -127,6 +126,7 @@ export class Mover {
if (!DraggerClass) throw new Error('no Dragger registered');
const dragger = new DraggerClass(block, workspace);
// Record that a move is in progress and start dragging.
workspace.setKeyboardMoveInProgress(true);
const info = new MoveInfo(block, dragger);
this.moves.set(workspace, info);
// Begin drag.
Expand Down Expand Up @@ -154,9 +154,9 @@ export class Mover {
new utils.Coordinate(0, 0),
);

this.unpatchWorkspace(workspace);
this.unpatchDragStrategy(info.block);
this.moves.delete(workspace);
workspace.setKeyboardMoveInProgress(false);
// Delay scroll until after block has finished moving.
setTimeout(() => this.scrollCurrentBlockIntoView(workspace), 0);
return true;
Expand Down Expand Up @@ -200,9 +200,9 @@ export class Mover {
if (newNode) workspace.getCursor()?.setCurNode(newNode);
}

this.unpatchWorkspace(workspace);
this.unpatchDragStrategy(info.block);
this.moves.delete(workspace);
workspace.setKeyboardMoveInProgress(false);
// Delay scroll until after block has finished moving.
setTimeout(() => this.scrollCurrentBlockIntoView(workspace), 0);
return true;
Expand Down Expand Up @@ -253,45 +253,6 @@ export class Mover {
return true;
}

/**
* Monkeypatch over workspace functions to consider keyboard drags as
* well as mouse/pointer drags.
*
* @param workspace The workspace to patch.
*/
private patchWorkspace(workspace: WorkspaceSvg) {
// Keyboard drags are real drags.
this.oldIsDragging = workspace.isDragging;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(workspace as any).isDragging = () => this.isMoving(workspace);

// Ignore mouse/pointer events during keyboard drags.
this.oldGetGesture = workspace.getGesture;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(workspace as any).getGesture = (e: PointerEvent) => {
// Normally these would be called from Gesture.doStart.
e.preventDefault();
e.stopPropagation();
return null;
};
}

/**
* Remove monkeypatches on the workspace.
*
* @param workspace The workspace to unpatch.
*/
private unpatchWorkspace(workspace: WorkspaceSvg) {
if (this.oldIsDragging) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(workspace as any).isDragging = this.oldIsDragging;
}
if (this.oldGetGesture) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(workspace as any).getGesture = this.oldGetGesture;
}
}

/**
* Monkeypatch: replace the block's drag strategy and cache the old value.
*
Expand Down
Loading