Another attempt to fix #904 to keep the page from jumping to the focused workspace in IE 11 (#974)

This commit is contained in:
picklesrus
2017-03-10 14:58:09 -08:00
committed by GitHub
parent 9b98573327
commit 847d83e4af
2 changed files with 12 additions and 3 deletions

View File

@@ -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() {

View File

@@ -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();
}
}
};