Skip to content

Commit 8f59649

Browse files
fix: LineCursor can loop forward, but not back (#8926)
* fix: loop cursor when moving to prev node * chore: add loop tests for LineCursor prev and out * chore: fix out loop test for line cursor
1 parent 5bc8380 commit 8f59649

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

core/keyboard_nav/line_cursor.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,12 @@ export class LineCursor extends Marker {
146146
if (!curNode) {
147147
return null;
148148
}
149-
const newNode = this.getPreviousNodeImpl(
149+
const newNode = this.getPreviousNode(
150150
curNode,
151151
this.validLineNode.bind(this),
152+
true,
152153
);
154+
153155
if (newNode) {
154156
this.setCurNode(newNode);
155157
}
@@ -168,9 +170,10 @@ export class LineCursor extends Marker {
168170
if (!curNode) {
169171
return null;
170172
}
171-
const newNode = this.getPreviousNodeImpl(
173+
const newNode = this.getPreviousNode(
172174
curNode,
173175
this.validInLineNode.bind(this),
176+
true,
174177
);
175178

176179
if (newNode) {

tests/mocha/cursor_test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ suite('Cursor', function () {
125125
assert.equal(curNode.getLocation(), this.blocks.A.nextConnection);
126126
});
127127

128+
test('Prev - From first connection loop to last next connection', function () {
129+
const prevConnection = this.blocks.A.previousConnection;
130+
const prevConnectionNode = ASTNode.createConnectionNode(prevConnection);
131+
this.cursor.setCurNode(prevConnectionNode);
132+
this.cursor.prev();
133+
const curNode = this.cursor.getCurNode();
134+
assert.equal(curNode.getLocation(), this.blocks.D.nextConnection);
135+
});
136+
128137
test('Out - From field does not skip over block node', function () {
129138
const field = this.blocks.E.inputList[0].fieldRow[0];
130139
const fieldNode = ASTNode.createFieldNode(field);
@@ -133,6 +142,15 @@ suite('Cursor', function () {
133142
const curNode = this.cursor.getCurNode();
134143
assert.equal(curNode.getLocation(), this.blocks.E);
135144
});
145+
146+
test('Out - From first connection loop to last next connection', function () {
147+
const prevConnection = this.blocks.A.previousConnection;
148+
const prevConnectionNode = ASTNode.createConnectionNode(prevConnection);
149+
this.cursor.setCurNode(prevConnectionNode);
150+
this.cursor.out();
151+
const curNode = this.cursor.getCurNode();
152+
assert.equal(curNode.getLocation(), this.blocks.D.nextConnection);
153+
});
136154
});
137155
suite('Searching', function () {
138156
setup(function () {

0 commit comments

Comments
 (0)