From 1fa6559e67e9c985bbed2707b700b25eb4fc19fb Mon Sep 17 00:00:00 2001 From: Erik Pasternak Date: Mon, 28 Apr 2025 12:22:25 -0700 Subject: [PATCH] feat: Add some additional padding during a constrained move --- src/actions/mover.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/actions/mover.ts b/src/actions/mover.ts index 922585cd..cd7ad2d3 100644 --- a/src/actions/mover.ts +++ b/src/actions/mover.ts @@ -31,6 +31,11 @@ import {clearMoveHints} from '../hints'; */ const UNCONSTRAINED_MOVE_DISTANCE = 20; +/** + * The amount of additional padding to include during a constrained move. + */ +const CONSTRAINED_ADDITIONAL_PADDING = 70; + /** * Low-level code for moving blocks with keyboard shortcuts. */ @@ -226,7 +231,7 @@ export class Mover { ); info.updateTotalDelta(); - this.scrollCurrentBlockIntoView(workspace); + this.scrollCurrentBlockIntoView(workspace, CONSTRAINED_ADDITIONAL_PADDING); return true; } @@ -326,13 +331,15 @@ export class Mover { * @param padding Amount of spacing to put between the bounds and the edge of * the workspace's viewport. */ - private scrollCurrentBlockIntoView(workspace: WorkspaceSvg, padding = 10) { + private scrollCurrentBlockIntoView(workspace: WorkspaceSvg, padding = 0) { const blockToView = this.moves.get(workspace)?.block; if (blockToView) { - workspace.scrollBoundsIntoView( - blockToView.getBoundingRectangleWithoutChildren(), - padding, - ); + const bounds = blockToView.getBoundingRectangleWithoutChildren().clone(); + bounds.top -= padding; + bounds.bottom += padding; + bounds.left -= padding; + bounds.right += padding; + workspace.scrollBoundsIntoView(bounds); } }