Merge pull request #297 from picklesrus/develop-perf-1

Remove Blockly.removeAllRanges and replace it with calls to add/remove
This commit is contained in:
Neil Fraser 2016-03-28 12:17:11 -07:00
commit 92f224dd52
9 changed files with 22 additions and 26 deletions

View file

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

View file

@ -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;

View file

@ -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;',

View file

@ -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.

View file

@ -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_);

View file

@ -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;

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');
}
};
/**

View file

@ -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;

View file

@ -702,7 +702,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;