From a202558950ce9b06825447ec79bbe9960f451715 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 6 Apr 2022 17:22:26 -0700 Subject: [PATCH] feat: Add margin around zoomToFit (#6042) * Add margin around zoomToFit * Change configurable property to fixed constant. * VS Code keeps indenting stuff for no reason. --- core/workspace_svg.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/workspace_svg.js b/core/workspace_svg.js index ea632409d..0ec4058d2 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -116,6 +116,12 @@ goog.require('Blockly.MetricsManager'); goog.require('Blockly.Msg'); +/** + * Margin around the top/bottom/left/right after a zoomToFit call. + * @const + */ +const ZOOM_TO_FIT_MARGIN = 20; + /** * Class for a workspace. This is an onscreen area with optional trashcan, * scrollbars, bubbles, and dragging. @@ -2168,8 +2174,9 @@ class WorkspaceSvg extends Workspace { let workspaceWidth = metrics.viewWidth; let workspaceHeight = metrics.viewHeight; const blocksBox = this.getBlocksBoundingBox(); - let blocksWidth = blocksBox.right - blocksBox.left; - let blocksHeight = blocksBox.bottom - blocksBox.top; + const doubleMargin = ZOOM_TO_FIT_MARGIN * 2; + let blocksWidth = blocksBox.right - blocksBox.left + doubleMargin; + let blocksHeight = blocksBox.bottom - blocksBox.top + doubleMargin; if (!blocksWidth) { return; // Prevents zooming to infinity. }