mirror of
https://github.com/google/blockly.git
synced 2026-01-08 17:40:09 +01:00
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:
@@ -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');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user