mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04: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:
parent
39fbd24659
commit
b11bd4fb71
9 changed files with 22 additions and 26 deletions
|
@ -488,6 +488,7 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) {
|
|||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
Blockly.setPageSelectable(false);
|
||||
this.workspace.markFocused();
|
||||
// Update Blockly's knowledge of its own location.
|
||||
Blockly.svgResize(this.workspace);
|
||||
|
@ -508,7 +509,6 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) {
|
|||
Blockly.Events.setGroup(true);
|
||||
}
|
||||
// Left-click (or middle click)
|
||||
Blockly.removeAllRanges();
|
||||
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
|
||||
|
||||
this.dragStartXY_ = this.getRelativeToSurfaceXY();
|
||||
|
@ -543,6 +543,7 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) {
|
|||
* @private
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.onMouseUp_ = function(e) {
|
||||
Blockly.setPageSelectable(true);
|
||||
Blockly.terminateDrag_();
|
||||
if (Blockly.selected && Blockly.highlightedConnection_) {
|
||||
// Connect two blocks together.
|
||||
|
@ -786,7 +787,6 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) {
|
|||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
Blockly.removeAllRanges();
|
||||
|
||||
var oldXY = this.getRelativeToSurfaceXY();
|
||||
var newXY = this.workspace.moveDrag(e);
|
||||
|
|
|
@ -170,7 +170,7 @@ Blockly.onMouseUp_ = function(e) {
|
|||
var workspace = Blockly.getMainWorkspace();
|
||||
Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);
|
||||
workspace.isScrolling = false;
|
||||
|
||||
Blockly.setPageSelectable(true);
|
||||
// Unbind the touch event if it exists.
|
||||
if (Blockly.onTouchUpWrapper_) {
|
||||
Blockly.unbindEvent_(Blockly.onTouchUpWrapper_);
|
||||
|
@ -193,7 +193,6 @@ Blockly.onMouseMove_ = function(e) {
|
|||
}
|
||||
var workspace = Blockly.getMainWorkspace();
|
||||
if (workspace.isScrolling) {
|
||||
Blockly.removeAllRanges();
|
||||
var dx = e.clientX - workspace.startDragMouseX;
|
||||
var dy = e.clientY - workspace.startDragMouseY;
|
||||
var metrics = workspace.startDragMetrics;
|
||||
|
|
|
@ -143,6 +143,13 @@ Blockly.Css.CONTENT = [
|
|||
'z-index: 999;',
|
||||
'}',
|
||||
|
||||
'.blocklyNonSelectable {',
|
||||
'user-select: none;',
|
||||
'-moz-user-select: none;',
|
||||
'-webkit-user-select: none;',
|
||||
'-ms-user-select: none;',
|
||||
'}',
|
||||
|
||||
'.blocklyTooltipDiv {',
|
||||
'background-color: #ffffc7;',
|
||||
'border: 1px solid #ddc;',
|
||||
|
|
|
@ -536,7 +536,6 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) {
|
|||
block.showContextMenu_(e);
|
||||
} else {
|
||||
// Left-click (or middle click)
|
||||
Blockly.removeAllRanges();
|
||||
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
|
||||
// Record the current mouse position.
|
||||
Blockly.Flyout.startDownEvent_ = e;
|
||||
|
@ -606,7 +605,6 @@ Blockly.Flyout.prototype.onMouseMoveBlock_ = function(e) {
|
|||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
Blockly.removeAllRanges();
|
||||
var dx = e.clientX - Blockly.Flyout.startDownEvent_.clientX;
|
||||
var dy = e.clientY - Blockly.Flyout.startDownEvent_.clientY;
|
||||
// Still dragging within the sticky DRAG_RADIUS.
|
||||
|
|
|
@ -442,6 +442,7 @@ Blockly.Scrollbar.prototype.onMouseDownKnob_ = function(e) {
|
|||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
Blockly.setPageSelectable(false);
|
||||
// Look up the current translation and record it.
|
||||
this.startDragKnob = parseFloat(
|
||||
this.svgKnob_.getAttribute(this.horizontal_ ? 'x' : 'y'));
|
||||
|
@ -474,7 +475,7 @@ Blockly.Scrollbar.prototype.onMouseMoveKnob_ = function(e) {
|
|||
* @private
|
||||
*/
|
||||
Blockly.Scrollbar.prototype.onMouseUpKnob_ = function() {
|
||||
Blockly.removeAllRanges();
|
||||
Blockly.setPageSelectable(true);
|
||||
Blockly.hideChaff(true);
|
||||
if (Blockly.Scrollbar.onMouseUpWrapper_) {
|
||||
Blockly.unbindEvent_(Blockly.Scrollbar.onMouseUpWrapper_);
|
||||
|
|
|
@ -390,7 +390,6 @@ Blockly.Toolbox.TreeControl.prototype.createNode = function(opt_html) {
|
|||
* @override
|
||||
*/
|
||||
Blockly.Toolbox.TreeControl.prototype.setSelectedItem = function(node) {
|
||||
Blockly.removeAllRanges();
|
||||
var toolbox = this.toolbox_;
|
||||
if (node == this.selectedItem_ || node == toolbox.tree_) {
|
||||
return;
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -571,6 +571,7 @@ Blockly.WorkspaceSvg.prototype.isDeleteArea = function(e) {
|
|||
*/
|
||||
Blockly.WorkspaceSvg.prototype.onMouseDown_ = function(e) {
|
||||
this.markFocused();
|
||||
Blockly.setPageSelectable(false);
|
||||
if (Blockly.isTargetInput_(e)) {
|
||||
return;
|
||||
}
|
||||
|
@ -588,7 +589,6 @@ Blockly.WorkspaceSvg.prototype.onMouseDown_ = function(e) {
|
|||
// Right-click.
|
||||
this.showContextMenu_(e);
|
||||
} else if (this.scrollbar) {
|
||||
Blockly.removeAllRanges();
|
||||
// If the workspace is editable, only allow scrolling when gripping empty
|
||||
// space. Otherwise, allow scrolling when gripping anywhere.
|
||||
this.isScrolling = true;
|
||||
|
|
|
@ -699,7 +699,6 @@ function updatePreview() {
|
|||
* @param {string} id ID of <pre> element to inject into.
|
||||
*/
|
||||
function injectCode(code, id) {
|
||||
Blockly.removeAllRanges();
|
||||
var pre = document.getElementById(id);
|
||||
pre.textContent = code;
|
||||
code = pre.innerHTML;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue