From 70cf3cdbec4d2def71b7cd5c0a5635a8aa44ec9e Mon Sep 17 00:00:00 2001 From: mark-friedman Date: Fri, 19 Nov 2021 14:02:24 -0800 Subject: [PATCH 1/4] Change getCandidate_ and showInsertionMarker_ to be more dynamic --- core/insertion_marker_manager.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index df86ecc8c89..5c51b6985e2 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -431,6 +431,13 @@ InsertionMarkerManager.prototype.getCandidate_ = function(dxy) { let candidateClosest = null; let candidateLocal = null; + // It's possible that a block has added or removed connections during a drag, + // (e.g. in a drag/move event handler), so let's update the available connections. + // Note that this will be called en every move while dragging, so ir might + // cause slowness, especially if the block stack is large. If so, maybe it + // could be made more efficient. + this.updateAvailableConnections(); + for (let i = 0; i < this.availableConnections_.length; i++) { const myConnection = this.availableConnections_[i]; const neighbour = myConnection.closest(radius, dxy); @@ -617,8 +624,21 @@ InsertionMarkerManager.prototype.showInsertionMarker_ = function() { const closest = this.closestConnection_; const isLastInStack = this.lastOnStack_ && local === this.lastOnStack_; - const imBlock = isLastInStack ? this.lastMarker_ : this.firstMarker_; - const imConn = imBlock.getMatchingConnection(local.getSourceBlock(), local); + let imBlock = isLastInStack ? this.lastMarker_ : this.firstMarker_; + let imConn; + try { + imConn = imBlock.getMatchingConnection(local.getSourceBlock(), local); + } catch (e) { + // It's possible that the number of connections on the local block has + // changed since the insertion marker was originally created. Let's recreate + // the insertion marker and try again. + // In theory we could probably recreate the marker block (e.g. in getCandidate_), + // which is called more often during the drag, but creating a block that + // often might be too slow, so we only do it if necessary. + this.firstMarker_ = this.createMarkerBlock_(this.topBlock_); + imBlock = isLastInStack ? this.lastMarker_ : this.firstMarker_; + imConn = imBlock.getMatchingConnection(local.getSourceBlock(), local); + } if (imConn === this.markerConnection_) { throw Error( From b1de9bb623d9dc20196688ca2ca0894e301ebec2 Mon Sep 17 00:00:00 2001 From: mark-friedman Date: Wed, 24 Nov 2021 17:01:48 -0800 Subject: [PATCH 2/4] Ran clang formatter --- core/insertion_marker_manager.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index 5c51b6985e2..3d28568a42f 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -432,10 +432,10 @@ InsertionMarkerManager.prototype.getCandidate_ = function(dxy) { let candidateLocal = null; // It's possible that a block has added or removed connections during a drag, - // (e.g. in a drag/move event handler), so let's update the available connections. - // Note that this will be called en every move while dragging, so ir might - // cause slowness, especially if the block stack is large. If so, maybe it - // could be made more efficient. + // (e.g. in a drag/move event handler), so let's update the available + // connections. Note that this will be called en every move while dragging, so + // ir might cause slowness, especially if the block stack is large. If so, + // maybe it could be made more efficient. this.updateAvailableConnections(); for (let i = 0; i < this.availableConnections_.length; i++) { @@ -630,11 +630,11 @@ InsertionMarkerManager.prototype.showInsertionMarker_ = function() { imConn = imBlock.getMatchingConnection(local.getSourceBlock(), local); } catch (e) { // It's possible that the number of connections on the local block has - // changed since the insertion marker was originally created. Let's recreate - // the insertion marker and try again. - // In theory we could probably recreate the marker block (e.g. in getCandidate_), - // which is called more often during the drag, but creating a block that - // often might be too slow, so we only do it if necessary. + // changed since the insertion marker was originally created. Let's + // recreate the insertion marker and try again. In theory we could probably + // recreate the marker block (e.g. in getCandidate_), which is called more + // often during the drag, but creating a block that often might be too slow, + // so we only do it if necessary. this.firstMarker_ = this.createMarkerBlock_(this.topBlock_); imBlock = isLastInStack ? this.lastMarker_ : this.firstMarker_; imConn = imBlock.getMatchingConnection(local.getSourceBlock(), local); From 6dc829c2cd0caaa9da2c5513154a6ec9302b3c92 Mon Sep 17 00:00:00 2001 From: mark-friedman Date: Mon, 29 Nov 2021 16:42:25 -0800 Subject: [PATCH 3/4] Fix typos --- core/insertion_marker_manager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index 3d28568a42f..182ccf65c20 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -433,8 +433,8 @@ InsertionMarkerManager.prototype.getCandidate_ = function(dxy) { // It's possible that a block has added or removed connections during a drag, // (e.g. in a drag/move event handler), so let's update the available - // connections. Note that this will be called en every move while dragging, so - // ir might cause slowness, especially if the block stack is large. If so, + // connections. Note that this will be called on every move while dragging, so + // it might cause slowness, especially if the block stack is large. If so, // maybe it could be made more efficient. this.updateAvailableConnections(); From 926cfd1c44c8197f7abd5f93ef9c0696e23018eb Mon Sep 17 00:00:00 2001 From: mark-friedman Date: Tue, 30 Nov 2021 11:04:49 -0800 Subject: [PATCH 4/4] Fix issue with dragging stacks * From PR comment --- core/insertion_marker_manager.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index 182ccf65c20..b2592d491de 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -435,8 +435,11 @@ InsertionMarkerManager.prototype.getCandidate_ = function(dxy) { // (e.g. in a drag/move event handler), so let's update the available // connections. Note that this will be called on every move while dragging, so // it might cause slowness, especially if the block stack is large. If so, - // maybe it could be made more efficient. - this.updateAvailableConnections(); + // maybe it could be made more efficient. Also note that we won't update the + // connections if we've already connected the insertion marker to a block. + if (!this.markerConnection_ || !this.markerConnection_.isConnected()) { + this.updateAvailableConnections(); + } for (let i = 0; i < this.availableConnections_.length; i++) { const myConnection = this.availableConnections_[i];