mirror of
https://github.com/google/blockly.git
synced 2026-03-10 07:10:11 +01:00
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:
@@ -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) {
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user