Skip to content

Commit da997e7

Browse files
feat: scroll moving block into view (#451)
* feat: scroll moving block into view * chore: tweak doc and format mover.ts * feat: add padding param (def to 0) for mover scroll into view * fix: correct default padding to 10 for move scroll to view * fix: bypass get cur block when move scroll into view The issue is that scrollBoundsIntoView in scrollCurrentBlockIntoView is not taking effect because it has already been called via getCurrentBlock (which eventually calls scrollBoundsIntoView in the call stack). To bypass getCurrentBlock, a new class variable for current block is set and reset for a move. * feat: set constrained move block spacing to 100 * Revert "feat: set constrained move block spacing to 100" This reverts commit 420c224. * Revert "fix: bypass get cur block when move scroll into view" This reverts commit 9657acd.
1 parent d3575fa commit da997e7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/actions/mover.ts

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

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

@@ -198,6 +202,7 @@ export class Mover {
198202
);
199203

200204
info.updateTotalDelta();
205+
this.scrollCurrentBlockIntoView(workspace);
201206
return true;
202207
}
203208

@@ -219,6 +224,7 @@ export class Mover {
219224
info.totalDelta.y += y * UNCONSTRAINED_MOVE_DISTANCE * workspace.scale;
220225

221226
info.dragger.onDrag(info.fakePointerEvent('pointermove'), info.totalDelta);
227+
this.scrollCurrentBlockIntoView(workspace);
222228
return true;
223229
}
224230

@@ -308,6 +314,23 @@ export class Mover {
308314
this.oldDragStrategy = null;
309315
}
310316
}
317+
318+
/**
319+
* Scrolls the current block into view if one exists.
320+
*
321+
* @param workspace The workspace to get current block from.
322+
* @param padding Amount of spacing to put between the bounds and the edge of
323+
* the workspace's viewport.
324+
*/
325+
private scrollCurrentBlockIntoView(workspace: WorkspaceSvg, padding = 10) {
326+
const blockToView = this.getCurrentBlock(workspace);
327+
if (blockToView) {
328+
workspace.scrollBoundsIntoView(
329+
blockToView.getBoundingRectangleWithoutChildren(),
330+
padding,
331+
);
332+
}
333+
}
311334
}
312335

313336
/**

0 commit comments

Comments
 (0)