Commit 345b0cb6 authored by Neil Fraser's avatar Neil Fraser

Remove selection in Block Factory when switching modes.

parent e3009310
This diff is collapsed.
......@@ -903,8 +903,6 @@ Blockly.Block.prototype.appendDummyInput = function(opt_name) {
*/
Blockly.Block.prototype.jsonInit = function(json) {
// Validate inputs.
goog.asserts.assertString(json['message0'], 'No message.');
goog.asserts.assertArray(json['args0'], 'No args.');
goog.asserts.assert(json['output'] == undefined ||
json['previousStatement'] == undefined,
'Must not have both an output and a previousStatement.');
......
......@@ -464,26 +464,6 @@ Blockly.hideChaff = function(opt_allowToolbox) {
}
};
/**
* 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.
*/
Blockly.removeAllRanges = function() {
if (getSelection()) {
setTimeout(function() {
try {
var selection = getSelection();
if (!selection.isCollapsed) {
selection.removeAllRanges();
}
} catch (e) {
// MSIE throws 'error 800a025e' here.
}
}, 0);
}
};
/**
* Return an object with all the metrics required to size scrollbars for the
* main workspace. The following properties are computed:
......
......@@ -325,6 +325,26 @@ Blockly.createSvgElement = function(name, attrs, opt_parent) {
return e;
};
/**
* 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.
*/
Blockly.removeAllRanges = function() {
if (getSelection()) {
setTimeout(function() {
try {
var selection = getSelection();
if (!selection.isCollapsed) {
selection.removeAllRanges();
}
} catch (e) {
// MSIE throws 'error 800a025e' here.
}
}, 0);
}
};
/**
* Is this event a right-click?
* @param {!Event} e Mouse event.
......
......@@ -62,6 +62,7 @@ function onchange() {
* Update the language code.
*/
function updateLanguage() {
Blockly.removeAllRanges();
var code = [];
var rootBlock = getRootBlock();
if (rootBlock) {
......@@ -495,6 +496,7 @@ function getTypesFrom_(block, name) {
* Update the generator code.
*/
function updateGenerator() {
Blockly.removeAllRanges();
function makeVar(root, name) {
name = name.toLowerCase().replace(/\W/g, '_');
return ' var ' + root + '_' + name;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment