From 71f72853339af288bf2491970589849ca792b3fd Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Mon, 23 Mar 2020 17:34:12 -0700 Subject: [PATCH] Fix mutator field scale (#3763) * Fix mutator zoom scale --- core/field_multilineinput.js | 2 +- core/field_textinput.js | 2 +- core/workspace_svg.js | 13 +++++++++++++ tests/mocha/field_textinput_test.js | 4 +++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index 4e2f7dfc2..734f4135a 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -208,7 +208,7 @@ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { */ Blockly.FieldMultilineInput.prototype.widgetCreate_ = function() { var div = Blockly.WidgetDiv.DIV; - var scale = this.workspace_.scale; + var scale = this.workspace_.getScale(); var htmlInput = /** @type {HTMLTextAreaElement} */ (document.createElement('textarea')); diff --git a/core/field_textinput.js b/core/field_textinput.js index b2c4d7ce6..2343a2232 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -330,7 +330,7 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { var htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); htmlInput.className = 'blocklyHtmlInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); - var scale = this.workspace_.scale; + var scale = this.workspace_.getScale(); var fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index b94fcf9c5..5896fb4ad 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -2152,6 +2152,19 @@ Blockly.WorkspaceSvg.prototype.setScale = function(newScale) { } }; + +/** + * Get the workspace's zoom factor. If the workspace has a parent, we call into + * the parent to get the workspace scale. + * @return {number} The workspace zoom factor. Units: (pixels / workspaceUnit). + */ +Blockly.WorkspaceSvg.prototype.getScale = function() { + if (this.options.parentWorkspace) { + return this.options.parentWorkspace.getScale(); + } + return this.scale; +}; + /** * Scroll the workspace to a specified offset (in pixels), keeping in the * workspace bounds. See comment on workspaceSvg.scrollX for more detail on diff --git a/tests/mocha/field_textinput_test.js b/tests/mocha/field_textinput_test.js index cb19004b4..a3acdec61 100644 --- a/tests/mocha/field_textinput_test.js +++ b/tests/mocha/field_textinput_test.js @@ -217,7 +217,9 @@ suite('Text Input Fields', function() { setup(function() { this.prepField = function(field) { var workspace = { - scale: 1, + getScale: function() { + return 1; + }, getRenderer: function() { return { getClassName: function() { return ''; } }; },