From 4432ca2e9312f292857143c779dc49751a2029a8 Mon Sep 17 00:00:00 2001 From: Monica Kozbial Date: Mon, 24 Feb 2020 13:35:36 -0800 Subject: [PATCH] Cleanup centerOnBlock. (#3699) --- core/workspace_svg.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 0c41274f9..202b23969 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -2075,31 +2075,26 @@ Blockly.WorkspaceSvg.prototype.centerOnBlock = function(id) { // Workspace scale, used to convert from workspace coordinates to pixels. var scale = this.scale; - // Center in pixels. 0, 0 is at the workspace origin. These numbers may - // be negative. + // Center of block in pixels, relative to workspace origin (center 0,0). + // Scrolling to here would put the block in the top-left corner of the + // visible workspace. var pixelX = blockCenterX * scale; var pixelY = blockCenterY * scale; var metrics = this.getMetrics(); - // Scrolling to here would put the block in the top-left corner of the - // visible workspace. - var scrollToBlockX = pixelX - metrics.contentLeft; - var scrollToBlockY = pixelY - metrics.contentTop; - // viewHeight and viewWidth are in pixels. var halfViewWidth = metrics.viewWidth / 2; var halfViewHeight = metrics.viewHeight / 2; // Put the block in the center of the visible workspace instead. - var scrollToCenterX = scrollToBlockX - halfViewWidth; - var scrollToCenterY = scrollToBlockY - halfViewHeight; + var scrollToCenterX = pixelX - halfViewWidth; + var scrollToCenterY = pixelY - halfViewHeight; // Convert from workspace directions to canvas directions. - var x = -scrollToCenterX - metrics.contentLeft; - var y = -scrollToCenterY - metrics.contentTop; + var x = -scrollToCenterX; + var y = -scrollToCenterY; - Blockly.hideChaff(); this.scroll(x, y); };