Skip to content

Commit 867b5bf

Browse files
authored
fix: Fix disconnecting blocks. (#316)
1 parent 0092431 commit 867b5bf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/actions/disconnect.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import {
88
ASTNode,
9+
BlockSvg,
910
RenderedConnection,
1011
ShortcutRegistry,
1112
utils as BlocklyUtils,
@@ -92,6 +93,19 @@ export class DisconnectAction {
9293
let curNode: ASTNode | null = cursor.getCurNode();
9394
let wasVisitingConnection = true;
9495
while (curNode && !curNode.isConnection()) {
96+
const location = curNode.getLocation();
97+
if (location instanceof BlockSvg) {
98+
const previous = location.previousConnection;
99+
const output = location.outputConnection;
100+
if (previous?.isConnected()) {
101+
curNode = ASTNode.createConnectionNode(previous);
102+
break;
103+
} else if (output?.isConnected()) {
104+
curNode = ASTNode.createConnectionNode(output);
105+
break;
106+
}
107+
}
108+
95109
curNode = curNode.out();
96110
wasVisitingConnection = false;
97111
}

0 commit comments

Comments
 (0)