diff --git a/core/workspace_svg.js b/core/workspace_svg.js index ea632409d85..0ec4058d261 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. }