Skip to content

Commit 52ae76b

Browse files
authored
feat: Allow LineCursor to be positioned between blocks (#162)
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.
1 parent 59fa664 commit 52ae76b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/line_cursor.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,14 @@ export class LineCursor extends Marker {
131131
const type = node && node.getType();
132132
switch (type) {
133133
case ASTNode.types.BLOCK:
134-
return !((location as Blockly.Block).outputConnection?.isConnected());
134+
return !(location as Blockly.Block).outputConnection?.isConnected();
135135
case ASTNode.types.INPUT:
136-
const connection = (location as Blockly.Connection);
137-
return connection.type === Blockly.NEXT_STATEMENT && !connection.isConnected();
136+
const connection = location as Blockly.Connection;
137+
return connection.type === Blockly.NEXT_STATEMENT;
138138
case ASTNode.types.NEXT:
139-
return !((location as Blockly.Connection).isConnected());
139+
return true;
140+
case ASTNode.types.PREVIOUS:
141+
return !(location as Blockly.Connection).isConnected();
140142
default:
141143
return false;
142144
}
@@ -164,7 +166,7 @@ export class LineCursor extends Marker {
164166
return true;
165167
case ASTNode.types.INPUT:
166168
case ASTNode.types.NEXT:
167-
return !((location as Blockly.Connection).isConnected());
169+
return !(location as Blockly.Connection).isConnected();
168170
case ASTNode.types.FIELD:
169171
return true;
170172
default:

0 commit comments

Comments
 (0)