From 847d83e4af756c674d7fcded0fe4f80f13542903 Mon Sep 17 00:00:00 2001 From: picklesrus Date: Fri, 10 Mar 2017 14:58:09 -0800 Subject: [PATCH] Another attempt to fix #904 to keep the page from jumping to the focused workspace in IE 11 (#974) --- core/inject.js | 5 +++-- core/workspace_svg.js | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) 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(); + } } };