Permalink
Browse files

Fix connection DB bug when workspace contains blocks with errors

Change-Id: I47f76f80ac48b37f2fb9bc82c174021fb918da0f
  • Loading branch information...
ewpatton authored and jisqyv committed Dec 6, 2018
1 parent 55b5834 commit f6f0160297b6a50e72bccd880e7ef063235fa13d
Showing with 19 additions and 0 deletions.
  1. +12 −0 appinventor/blocklyeditor/src/connection_db.js
  2. +7 −0 appinventor/blocklyeditor/src/workspace_svg.js
@@ -78,3 +78,15 @@ Blockly.ConnectionDB.prototype.removeConnection_ = function(connection) {
this.splice(removalIndex, 1);
}
};

/**
* O(n) removal of duplicate connections.
*/
Blockly.ConnectionDB.prototype.removeDupes = function() {
for (var i = 0; i < this.length - 1; i++) {
if (this[i] == this[i+1]) {
this.splice(i, 1);
i--;
}
}
};
@@ -1063,6 +1063,13 @@ Blockly.WorkspaceSvg.prototype.sortConnectionDB = function() {
connectionDB.sort(function(a, b) {
return a.y_ - b.y_;
});
// If we are rerendering due to a new error, we only redraw the error block, which means that
// we can't clear the database, otherwise all other connections disappear. Instead, we add
// the moved connections anyway, and at this point we can remove the duplicate entries in the
// database. We remove after sorting so that the operation is O(n) rather than O(n^2). This
// assumption may break in the future if Blockly decides on a different mechanism for indexing
// connections.
connectionDB.removeDupes();
});
};

0 comments on commit f6f0160

Please sign in to comment.