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
This commit is contained in:
Grace
2025-04-25 16:26:58 +01:00
committed by GitHub
parent 5bc83808bf
commit 8f59649956
2 changed files with 23 additions and 2 deletions

View File

@@ -146,10 +146,12 @@ export class LineCursor extends Marker {
if (!curNode) {
return null;
}
const newNode = this.getPreviousNodeImpl(
const newNode = this.getPreviousNode(
curNode,
this.validLineNode.bind(this),
true,
);
if (newNode) {
this.setCurNode(newNode);
}
@@ -168,9 +170,10 @@ export class LineCursor extends Marker {
if (!curNode) {
return null;
}
const newNode = this.getPreviousNodeImpl(
const newNode = this.getPreviousNode(
curNode,
this.validInLineNode.bind(this),
true,
);
if (newNode) {

View File

@@ -125,6 +125,15 @@ suite('Cursor', function () {
assert.equal(curNode.getLocation(), this.blocks.A.nextConnection);
});
test('Prev - From first connection loop to last next connection', function () {
const prevConnection = this.blocks.A.previousConnection;
const prevConnectionNode = ASTNode.createConnectionNode(prevConnection);
this.cursor.setCurNode(prevConnectionNode);
this.cursor.prev();
const curNode = this.cursor.getCurNode();
assert.equal(curNode.getLocation(), this.blocks.D.nextConnection);
});
test('Out - From field does not skip over block node', function () {
const field = this.blocks.E.inputList[0].fieldRow[0];
const fieldNode = ASTNode.createFieldNode(field);
@@ -133,6 +142,15 @@ suite('Cursor', function () {
const curNode = this.cursor.getCurNode();
assert.equal(curNode.getLocation(), this.blocks.E);
});
test('Out - From first connection loop to last next connection', function () {
const prevConnection = this.blocks.A.previousConnection;
const prevConnectionNode = ASTNode.createConnectionNode(prevConnection);
this.cursor.setCurNode(prevConnectionNode);
this.cursor.out();
const curNode = this.cursor.getCurNode();
assert.equal(curNode.getLocation(), this.blocks.D.nextConnection);
});
});
suite('Searching', function () {
setup(function () {