Remove selection in Block Factory when switching modes.

This commit is contained in:
Neil Fraser
2015-06-29 17:06:36 -07:00
parent e300931071
commit 345b0cb668
5 changed files with 28 additions and 27 deletions

View File

@@ -325,6 +325,26 @@ Blockly.createSvgElement = function(name, attrs, opt_parent) {
return e;
};
/**
* Deselect any selections on the webpage.
* Chrome will select text outside the SVG when double-clicking.
* Deselect this text, so that it doesn't mess up any subsequent drag.
*/
Blockly.removeAllRanges = function() {
if (getSelection()) {
setTimeout(function() {
try {
var selection = getSelection();
if (!selection.isCollapsed) {
selection.removeAllRanges();
}
} catch (e) {
// MSIE throws 'error 800a025e' here.
}
}, 0);
}
};
/**
* Is this event a right-click?
* @param {!Event} e Mouse event.