diff --git a/core/inject.js b/core/inject.js index 2255c84bc..54509db71 100644 --- a/core/inject.js +++ b/core/inject.js @@ -65,7 +65,8 @@ Blockly.inject = function(container, opt_options) { var workspace = Blockly.createMainWorkspace_(svg, options, blockDragSurface, workspaceDragSurface); Blockly.init_(workspace); - workspace.markFocused(); + Blockly.mainWorkspace = workspace; + Blockly.svgResize(workspace); return workspace; }; @@ -212,7 +213,7 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface, workspac // A null translation will also apply the correct initial scale. mainWorkspace.translate(0, 0); - mainWorkspace.markFocused(); + Blockly.mainWorkspace = mainWorkspace; if (!options.readOnly && !options.hasScrollbars) { var workspaceChanged = function() { diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 74282ab65..77600be3b 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1391,7 +1391,15 @@ Blockly.WorkspaceSvg.prototype.setBrowserFocus = function() { // IE and Edge do not support focus on SVG elements. When that fails // above, get the injectionDiv (the workspace's parent) and focus that // instead. This doesn't work in Chrome. - this.getParentSvg().parentNode.focus(); + try { + // In IE11, use setActive (which is IE only) so the page doesn't scroll + // to the workspace gaining focus. + this.getParentSvg().parentNode.setActive(); + } catch (e) { + // setActive support was discontinued in Edge so when that fails, call + // focus instead. + this.getParentSvg().parentNode.focus(); + } } };