Skip to content

Commit 3691c2d

Browse files
authored
Merge branch 'main' into test-fixes-and-additions-for-tab-nav
2 parents f737796 + 18c3ad3 commit 3691c2d

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

src/actions/mover.ts

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,14 @@ export class Mover {
152152
* @returns True iff move successfully finished.
153153
*/
154154
finishMove(workspace: WorkspaceSvg) {
155-
clearMoveHints(workspace);
156-
157-
const info = this.moves.get(workspace);
158-
if (!info) throw new Error('no move info for workspace');
159-
160-
// Remove the blur listener before ending the drag
161-
info.block
162-
.getFocusableElement()
163-
.removeEventListener('blur', info.blurListener);
155+
const info = this.preDragEndCleanup(workspace);
164156

165157
info.dragger.onDragEnd(
166158
info.fakePointerEvent('pointerup'),
167159
new utils.Coordinate(0, 0),
168160
);
169161

170-
this.unpatchDragStrategy(info.block);
171-
this.moves.delete(workspace);
172-
workspace.setKeyboardMoveInProgress(false);
173-
// Delay scroll until after block has finished moving.
174-
setTimeout(() => this.scrollCurrentBlockIntoView(workspace), 0);
175-
// If the block gets reattached, ensure it retains focus.
176-
getFocusManager().focusNode(info.block);
162+
this.postDragEndCleanup(workspace, info);
177163
return true;
178164
}
179165

@@ -186,10 +172,7 @@ export class Mover {
186172
* @returns True iff move successfully aborted.
187173
*/
188174
abortMove(workspace: WorkspaceSvg) {
189-
clearMoveHints(workspace);
190-
191-
const info = this.moves.get(workspace);
192-
if (!info) throw new Error('no move info for workspace');
175+
const info = this.preDragEndCleanup(workspace);
193176

194177
const dragStrategy = info.block.getDragStrategy() as KeyboardDragStrategy;
195178
this.patchDragger(
@@ -214,14 +197,44 @@ export class Mover {
214197
workspace.getCursor()?.setCurNode(target);
215198
}
216199

200+
this.postDragEndCleanup(workspace, info);
201+
return true;
202+
}
203+
204+
/**
205+
* Common clean-up for finish/abort.
206+
*
207+
* @param workspace The workspace on which we are moving.
208+
* @returns The info for the block.
209+
*/
210+
private preDragEndCleanup(workspace: WorkspaceSvg) {
211+
clearMoveHints(workspace);
212+
213+
const info = this.moves.get(workspace);
214+
if (!info) throw new Error('no move info for workspace');
215+
216+
// Remove the blur listener before ending the drag
217+
info.block
218+
.getFocusableElement()
219+
.removeEventListener('blur', info.blurListener);
220+
221+
return info;
222+
}
223+
224+
/**
225+
* Common clean-up for finish/abort.
226+
*
227+
* @param workspace The workspace on which we are moving.
228+
* @param info The info for the block.
229+
*/
230+
private postDragEndCleanup(workspace: WorkspaceSvg, info: MoveInfo) {
217231
this.unpatchDragStrategy(info.block);
218232
this.moves.delete(workspace);
219233
workspace.setKeyboardMoveInProgress(false);
220234
// Delay scroll until after block has finished moving.
221235
setTimeout(() => this.scrollCurrentBlockIntoView(workspace), 0);
222236
// If the block gets reattached, ensure it retains focus.
223237
getFocusManager().focusNode(info.block);
224-
return true;
225238
}
226239

227240
/**

0 commit comments

Comments
 (0)