diff --git a/core/block_svg.js b/core/block_svg.js index 04d59cc5d..4ea6f288d 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -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); diff --git a/core/blockly.js b/core/blockly.js index 8f6359555..67213067a 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -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; diff --git a/core/css.js b/core/css.js index f1cafb0a9..7e6f8be93 100644 --- a/core/css.js +++ b/core/css.js @@ -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;', diff --git a/core/flyout.js b/core/flyout.js index 7663e45cb..e69a73c6f 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -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. diff --git a/core/scrollbar.js b/core/scrollbar.js index 860a92195..42d053cc0 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -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_); diff --git a/core/toolbox.js b/core/toolbox.js index 494b08d71..c8818be1c 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -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; diff --git a/core/utils.js b/core/utils.js index 062909415..02d07df4f 100644 --- a/core/utils.js +++ b/core/utils.js @@ -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'); + } }; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index b93a90c85..bd1d031e1 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -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; diff --git a/demos/blockfactory/factory.js b/demos/blockfactory/factory.js index 4cda24f80..002b438d5 100644 --- a/demos/blockfactory/factory.js +++ b/demos/blockfactory/factory.js @@ -702,7 +702,6 @@ function updatePreview() { * @param {string} id ID of
element to inject into.
*/
function injectCode(code, id) {
- Blockly.removeAllRanges();
var pre = document.getElementById(id);
pre.textContent = code;
code = pre.innerHTML;