diff --git a/core/flyout.js b/core/flyout.js index 5319d91c..5169808f 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -652,6 +652,9 @@ Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) { // Scale the scroll (getSvgXY_ did not do this). xyNew.x += workspace.scrollX / workspace.scale - workspace.scrollX; xyNew.y += workspace.scrollY / workspace.scale - workspace.scrollY; + if (workspace.toolbox_ && !workspace.scrollbar) { + xyNew.x += workspace.toolbox_.width / workspace.scale; + } block.moveBy(xyOld.x - xyNew.x, xyOld.y - xyNew.y); if (flyout.autoClose) { flyout.hide(); diff --git a/core/inject.js b/core/inject.js index bf8a29c1..9632cbe8 100644 --- a/core/inject.js +++ b/core/inject.js @@ -376,6 +376,8 @@ Blockly.createMainWorkspace_ = function(svg, options) { var mainWorkspace = new Blockly.WorkspaceSvg(options); mainWorkspace.scale = options.zoomOptions.startScale; svg.appendChild(mainWorkspace.createDom('blocklyMainBackground')); + // A null translation will also apply the correct initial scale. + mainWorkspace.translate(0, 0); mainWorkspace.markFocused(); if (!options.readOnly && !options.hasScrollbars) { diff --git a/core/workspace_svg.js b/core/workspace_svg.js index e5fdbe57..9479064c 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -317,7 +317,7 @@ Blockly.WorkspaceSvg.prototype.getBubbleCanvas = function() { * @param {number} y Vertical translation. */ Blockly.WorkspaceSvg.prototype.translate = function(x, y) { - var translation = 'translate(' + x + ',' + y + ')' + + var translation = 'translate(' + x + ',' + y + ') ' + 'scale(' + this.scale + ')'; this.svgBlockCanvas_.setAttribute('transform', translation); this.svgBubbleCanvas_.setAttribute('transform', translation); @@ -922,7 +922,11 @@ Blockly.WorkspaceSvg.prototype.zoom = function(x, y, type) { this.scrollX = matrix.e - metrics.absoluteLeft; this.scrollY = matrix.f - metrics.absoluteTop; this.updateGridPattern_(); - this.scrollbar.resize(); + if (this.scrollbar) { + this.scrollbar.resize(); + } else { + this.translate(0, 0); + } Blockly.hideChaff(false); if (this.flyout_) { // No toolbox, resize flyout. @@ -959,8 +963,12 @@ Blockly.WorkspaceSvg.prototype.zoomReset = function(e) { } // Center the workspace. var metrics = this.getMetrics(); - this.scrollbar.set((metrics.contentWidth - metrics.viewWidth) / 2, - (metrics.contentHeight - metrics.viewHeight) / 2); + if (this.scrollbar) { + this.scrollbar.set((metrics.contentWidth - metrics.viewWidth) / 2, + (metrics.contentHeight - metrics.viewHeight) / 2); + } else { + this.translate(0, 0); + } // This event has been handled. Don't start a workspace drag. e.stopPropagation(); }; diff --git a/tests/playground.html b/tests/playground.html index 7e37763b..2f3ebc7c 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -86,7 +86,7 @@ function start() { zoom: {controls: true, wheel: true, - startScale: 2.0, + startScale: 1.0, maxScale: 4, minScale: .25, scaleSpeed: 1.1