Skip to content
Merged
Changes from 2 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
13 changes: 12 additions & 1 deletion src/actions/mover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,21 @@ export class Mover {
);
if (!DraggerClass) throw new Error('no Dragger registered');
const dragger = new DraggerClass(block, workspace);
// Set up a blur listener to end the move if the user clicks away
const blurListener = () => {
this.finishMove(workspace);
};
// Record that a move is in progress and start dragging.
workspace.setKeyboardMoveInProgress(true);
const info = new MoveInfo(block, dragger);
const info = new MoveInfo(block, dragger, blurListener);
this.moves.set(workspace, info);
// Begin drag.
dragger.onDragStart(info.fakePointerEvent('pointerdown'));
info.updateTotalDelta();
// In case the block is detached, ensure that it still retains focus
// (otherwise dragging will break).
getFocusManager().focusNode(block);
block.getFocusableElement().addEventListener('blur', blurListener);
return true;
}

Expand All @@ -152,6 +157,11 @@ export class Mover {
const info = this.moves.get(workspace);
if (!info) throw new Error('no move info for workspace');

// Remove the blur listener before ending the drag
info.block
.getFocusableElement()
.removeEventListener('blur', info.blurListener);

info.dragger.onDragEnd(
info.fakePointerEvent('pointerup'),
new utils.Coordinate(0, 0),
Expand Down Expand Up @@ -341,6 +351,7 @@ export class MoveInfo {
constructor(
readonly block: BlockSvg,
readonly dragger: IDragger,
readonly blurListener: EventListener,
) {
this.parentNext = block.previousConnection?.targetConnection ?? null;
this.parentInput = block.outputConnection?.targetConnection ?? null;
Expand Down
Loading