Skip to content

Commit

Permalink
feat: Allow LineCursor to be positioned between blocks (#162)
Browse files Browse the repository at this point in the history
Previously, the LineCursor could only visit next connections, and
only if they were not connected to another block.  This was to
allow the first block to be placed in a statement input, and to
make it easier to place new blocks on the bottom of a stack.

This change allows the LineCursor to visit ALL next connections,
and also to visit unconnected previous connections.  This allows
the cursor to be positioned between blocks in a stack, as well as
on the top connection of a statement input (on the input's
connection, since there may or may not be an attached block),
as well as on the previous connection of any top-level block
that has a previous connection.

This change is being made in response to comments from @kmcnaught:

- #129 (comment)
- #130 (comment)

... but should (like everything else in this repo) be considered
experimental and subject to further discussion / evaluation /
decisions.
  • Loading branch information
cpcallen authored Jan 20, 2025
1 parent 59fa664 commit 52ae76b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/line_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,14 @@ export class LineCursor extends Marker {
const type = node && node.getType();
switch (type) {
case ASTNode.types.BLOCK:
return !((location as Blockly.Block).outputConnection?.isConnected());
return !(location as Blockly.Block).outputConnection?.isConnected();
case ASTNode.types.INPUT:
const connection = (location as Blockly.Connection);
return connection.type === Blockly.NEXT_STATEMENT && !connection.isConnected();
const connection = location as Blockly.Connection;
return connection.type === Blockly.NEXT_STATEMENT;
case ASTNode.types.NEXT:
return !((location as Blockly.Connection).isConnected());
return true;
case ASTNode.types.PREVIOUS:
return !(location as Blockly.Connection).isConnected();
default:
return false;
}
Expand Down Expand Up @@ -164,7 +166,7 @@ export class LineCursor extends Marker {
return true;
case ASTNode.types.INPUT:
case ASTNode.types.NEXT:
return !((location as Blockly.Connection).isConnected());
return !(location as Blockly.Connection).isConnected();
case ASTNode.types.FIELD:
return true;
default:
Expand Down

0 comments on commit 52ae76b

Please sign in to comment.