Remove Blockly.removeAllRanges and replace it with calls to add/remove

css to mark text as unselectable instead.  I can't prove this is
significantly faster with numbers since the call to setup the time out
costs ~.1ms and the call when the timer fires is ~.05.  This happens on almost
every mouse event though.  Plus, it seems to remove a flicker of highlighting when
frames are skipped and keeps scrolling via the scrollbar from highlighting.
This commit is contained in:
Katelyn Mann
2016-03-23 14:39:02 -07:00
parent 39fbd24659
commit b11bd4fb71
9 changed files with 22 additions and 26 deletions

View File

@@ -347,23 +347,16 @@ Blockly.createSvgElement = function(name, attrs, parent, opt_workspace) {
};
/**
* 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.
* Set css classes to allow/disallow the browser from selecting/highlighting
* text, etc. on the page.
* @param {boolean} selectable Whether elements on the page can be selected.
*/
Blockly.removeAllRanges = function() {
if (window.getSelection) {
setTimeout(function() {
try {
var selection = window.getSelection();
if (!selection.isCollapsed) {
selection.removeAllRanges();
}
} catch (e) {
// MSIE throws 'error 800a025e' here.
}
}, 0);
}
Blockly.setPageSelectable = function(selectable) {
if (selectable) {
Blockly.removeClass_(document.body, 'blocklyNonSelectable');
} else {
Blockly.addClass_(document.body, 'blocklyNonSelectable');
}
};
/**