feat: Add margin around zoomToFit (#6042)

* Add margin around zoomToFit

* Change configurable property to fixed constant.

* VS Code keeps indenting stuff for no reason.
This commit is contained in:
Neil Fraser
2022-04-06 17:22:26 -07:00
committed by GitHub
parent 7991c8aeb3
commit a202558950

View File

@@ -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.
}