Skip to content

Commit 726bdfe

Browse files
feat: scroll moving block into view
1 parent c7265cf commit 726bdfe

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/actions/mover.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ export class Mover {
144144
this.unpatchWorkspace(workspace);
145145
this.unpatchDragStrategy(info.block);
146146
this.moves.delete(workspace);
147+
// Delay scroll until after block has finished moving.
148+
setTimeout(() => this.scrollCurrentBlockIntoView(workspace), 0)
147149
return true;
148150
}
149151

@@ -175,6 +177,8 @@ export class Mover {
175177
this.unpatchWorkspace(workspace);
176178
this.unpatchDragStrategy(info.block);
177179
this.moves.delete(workspace);
180+
// Delay scroll until after block has finished moving.
181+
setTimeout(() => this.scrollCurrentBlockIntoView(workspace), 0)
178182
return true;
179183
}
180184

@@ -197,6 +201,7 @@ export class Mover {
197201
);
198202

199203
info.updateTotalDelta();
204+
this.scrollCurrentBlockIntoView(workspace);
200205
return true;
201206
}
202207

@@ -218,6 +223,7 @@ export class Mover {
218223
info.totalDelta.y += y * UNCONSTRAINED_MOVE_DISTANCE * workspace.scale;
219224

220225
info.dragger.onDrag(info.fakePointerEvent('pointermove'), info.totalDelta);
226+
this.scrollCurrentBlockIntoView(workspace);
221227
return true;
222228
}
223229

@@ -307,6 +313,20 @@ export class Mover {
307313
this.oldDragStrategy = null;
308314
}
309315
}
316+
317+
/**
318+
* Scrolls the current block into view if exists one.
319+
*
320+
* @param workspace The workspace to get current block from.
321+
*/
322+
private scrollCurrentBlockIntoView(workspace: WorkspaceSvg) {
323+
const blockToView = this.getCurrentBlock(workspace);
324+
if (blockToView) {
325+
workspace.scrollBoundsIntoView(
326+
blockToView.getBoundingRectangleWithoutChildren(),
327+
);
328+
}
329+
}
310330
}
311331

312332
/**

0 commit comments

Comments
 (0)