Skip to content

Commit ed79dd6

Browse files
authored
Merge branch 'main' into nesky_block_nav_tests
2 parents 0ebb1bc + 6869679 commit ed79dd6

File tree

2 files changed

+19
-47
lines changed

2 files changed

+19
-47
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
*

src/actions/undo_redo.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {ShortcutRegistry, ShortcutItems, WorkspaceSvg} from 'blockly/core';
7+
import {
8+
ContextMenuRegistry,
9+
ShortcutRegistry,
10+
ShortcutItems,
11+
WorkspaceSvg,
12+
} from 'blockly/core';
813

914
/**
1015
* Class for registering a shortcut for undo/redo actions.
@@ -22,9 +27,12 @@ export class UndoRedoAction {
2227
this.originalUndo = undo;
2328
const patchedUndo = {
2429
...this.originalUndo,
25-
preconditionFn: (workspace: WorkspaceSvg) => {
30+
preconditionFn: (
31+
workspace: WorkspaceSvg,
32+
scope: ContextMenuRegistry.Scope,
33+
) => {
2634
return !!(
27-
!workspace.isDragging() && undo.preconditionFn?.(workspace)
35+
!workspace.isDragging() && undo.preconditionFn?.(workspace, scope)
2836
);
2937
},
3038
allowCollision: true,
@@ -39,9 +47,12 @@ export class UndoRedoAction {
3947
this.originalRedo = redo;
4048
const patchedRedo = {
4149
...this.originalRedo,
42-
preconditionFn: (workspace: WorkspaceSvg) => {
50+
preconditionFn: (
51+
workspace: WorkspaceSvg,
52+
scope: ContextMenuRegistry.Scope,
53+
) => {
4354
return !!(
44-
!workspace.isDragging() && redo.preconditionFn?.(workspace)
55+
!workspace.isDragging() && redo.preconditionFn?.(workspace, scope)
4556
);
4657
},
4758
allowCollision: true,

0 commit comments

Comments
 (0)