Skip to content

Commit

Permalink
feat: Make disconnection work on blocks and fields (#116)
Browse files Browse the repository at this point in the history
Fixes #93.
  • Loading branch information
cpcallen authored Nov 11, 2024
1 parent 0913c2e commit 6d7307f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,11 +1057,14 @@ export class Navigation {
if (!cursor) {
return;
}
const curNode = cursor.getCurNode();
if (!curNode.isConnection()) {
this.log(
'Cannot disconnect blocks when the cursor is not on a connection',
);
let curNode: Blockly.ASTNode | null = cursor.getCurNode();
let wasVisitingConnection = true;
while (curNode && !curNode.isConnection()) {
curNode = curNode.out();
wasVisitingConnection = false;
}
if (!curNode) {
this.log('Unable to find a connection to disconnect');
return;
}
const curConnection = curNode.getLocation() as Blockly.RenderedConnection;
Expand All @@ -1087,9 +1090,11 @@ export class Navigation {
const rootBlock = superiorConnection.getSourceBlock().getRootBlock();
rootBlock.bringToFront();

const connectionNode =
Blockly.ASTNode.createConnectionNode(superiorConnection);
workspace.getCursor()!.setCurNode(connectionNode!);
if (wasVisitingConnection) {
const connectionNode =
Blockly.ASTNode.createConnectionNode(superiorConnection);
workspace.getCursor()!.setCurNode(connectionNode!);
}
}

/**
Expand Down

0 comments on commit 6d7307f

Please sign in to comment.