mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
Fix: don't visit connections with the cursor. (#9030)
This commit is contained in:
@@ -97,34 +97,34 @@ suite('Cursor', function () {
|
||||
this.cursor.setCurNode(prevNode);
|
||||
this.cursor.next();
|
||||
const curNode = this.cursor.getCurNode();
|
||||
assert.equal(curNode, this.blocks.B.getInput('NAME4').connection);
|
||||
assert.equal(curNode, this.blocks.C);
|
||||
});
|
||||
|
||||
test('In - From attached input connection', function () {
|
||||
test('In - From field to attached input connection', function () {
|
||||
const fieldBlock = this.blocks.E;
|
||||
const inputConnectionNode = this.blocks.A.inputList[0].connection;
|
||||
this.cursor.setCurNode(inputConnectionNode);
|
||||
const fieldNode = this.blocks.A.getField('NAME2');
|
||||
this.cursor.setCurNode(fieldNode);
|
||||
this.cursor.in();
|
||||
const curNode = this.cursor.getCurNode();
|
||||
assert.equal(curNode, fieldBlock);
|
||||
});
|
||||
|
||||
test('Prev - From previous connection does not skip over next connection', function () {
|
||||
test('Prev - From previous connection does skip over next connection', function () {
|
||||
const prevConnection = this.blocks.B.previousConnection;
|
||||
const prevConnectionNode = prevConnection;
|
||||
this.cursor.setCurNode(prevConnectionNode);
|
||||
this.cursor.prev();
|
||||
const curNode = this.cursor.getCurNode();
|
||||
assert.equal(curNode, this.blocks.A.nextConnection);
|
||||
assert.equal(curNode, this.blocks.A);
|
||||
});
|
||||
|
||||
test('Prev - From first connection loop to last next connection', function () {
|
||||
const prevConnection = this.blocks.A.previousConnection;
|
||||
test('Prev - From first block loop to last block', function () {
|
||||
const prevConnection = this.blocks.A;
|
||||
const prevConnectionNode = prevConnection;
|
||||
this.cursor.setCurNode(prevConnectionNode);
|
||||
this.cursor.prev();
|
||||
const curNode = this.cursor.getCurNode();
|
||||
assert.equal(curNode, this.blocks.D.nextConnection);
|
||||
assert.equal(curNode, this.blocks.D);
|
||||
});
|
||||
|
||||
test('Out - From field does not skip over block node', function () {
|
||||
@@ -225,11 +225,11 @@ suite('Cursor', function () {
|
||||
});
|
||||
test('getFirstNode', function () {
|
||||
const node = this.cursor.getFirstNode();
|
||||
assert.equal(node, this.blockA.previousConnection);
|
||||
assert.equal(node, this.blockA);
|
||||
});
|
||||
test('getLastNode', function () {
|
||||
const node = this.cursor.getLastNode();
|
||||
assert.equal(node, this.blockA.nextConnection);
|
||||
assert.equal(node, this.blockA);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -242,11 +242,11 @@ suite('Cursor', function () {
|
||||
});
|
||||
test('getFirstNode', function () {
|
||||
const node = this.cursor.getFirstNode();
|
||||
assert.equal(node, this.blockA.outputConnection);
|
||||
assert.equal(node, this.blockA);
|
||||
});
|
||||
test('getLastNode', function () {
|
||||
const node = this.cursor.getLastNode();
|
||||
assert.equal(node, this.blockA.inputList[0].connection);
|
||||
assert.equal(node, this.blockA);
|
||||
});
|
||||
});
|
||||
suite('one c-hat block', function () {
|
||||
@@ -262,7 +262,7 @@ suite('Cursor', function () {
|
||||
});
|
||||
test('getLastNode', function () {
|
||||
const node = this.cursor.getLastNode();
|
||||
assert.equal(node, this.blockA.inputList[0].connection);
|
||||
assert.equal(node, this.blockA);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -295,12 +295,12 @@ suite('Cursor', function () {
|
||||
test('getFirstNode', function () {
|
||||
const node = this.cursor.getFirstNode();
|
||||
const blockA = this.workspace.getBlockById('A');
|
||||
assert.equal(node, blockA.previousConnection);
|
||||
assert.equal(node, blockA);
|
||||
});
|
||||
test('getLastNode', function () {
|
||||
const node = this.cursor.getLastNode();
|
||||
const blockB = this.workspace.getBlockById('B');
|
||||
assert.equal(node, blockB.nextConnection);
|
||||
assert.equal(node, blockB);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -335,12 +335,12 @@ suite('Cursor', function () {
|
||||
test('getFirstNode', function () {
|
||||
const node = this.cursor.getFirstNode();
|
||||
const blockA = this.workspace.getBlockById('A');
|
||||
assert.equal(node, blockA.outputConnection);
|
||||
assert.equal(node, blockA);
|
||||
});
|
||||
test('getLastNode', function () {
|
||||
const node = this.cursor.getLastNode();
|
||||
const blockB = this.workspace.getBlockById('B');
|
||||
assert.equal(node, blockB.inputList[0].connection);
|
||||
assert.equal(node, blockB);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -385,15 +385,14 @@ suite('Cursor', function () {
|
||||
test('getFirstNode', function () {
|
||||
const node = this.cursor.getFirstNode();
|
||||
const location = node;
|
||||
const previousConnection =
|
||||
this.workspace.getBlockById('A').previousConnection;
|
||||
assert.equal(location, previousConnection);
|
||||
const blockA = this.workspace.getBlockById('A');
|
||||
assert.equal(location, blockA);
|
||||
});
|
||||
test('getLastNode', function () {
|
||||
const node = this.cursor.getLastNode();
|
||||
const location = node;
|
||||
const nextConnection = this.workspace.getBlockById('D').nextConnection;
|
||||
assert.equal(location, nextConnection);
|
||||
const blockD = this.workspace.getBlockById('D');
|
||||
assert.equal(location, blockD);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -439,8 +438,8 @@ suite('Cursor', function () {
|
||||
this.cursor = this.workspace.getCursor();
|
||||
this.neverValid = () => false;
|
||||
this.alwaysValid = () => true;
|
||||
this.isConnection = (node) => {
|
||||
return node && node instanceof Blockly.RenderedConnection;
|
||||
this.isBlock = (node) => {
|
||||
return node && node instanceof Blockly.BlockSvg;
|
||||
};
|
||||
});
|
||||
teardown(function () {
|
||||
@@ -528,7 +527,7 @@ suite('Cursor', function () {
|
||||
assert.equal(nextNode, this.blockB.getField('FIELD'));
|
||||
});
|
||||
test('Always valid - start at end', function () {
|
||||
const startNode = this.blockC.nextConnection;
|
||||
const startNode = this.blockC.getField('FIELD');
|
||||
const nextNode = this.cursor.getNextNode(
|
||||
startNode,
|
||||
this.alwaysValid,
|
||||
@@ -537,29 +536,29 @@ suite('Cursor', function () {
|
||||
assert.isNull(nextNode);
|
||||
});
|
||||
|
||||
test('Valid if connection - start at top', function () {
|
||||
const startNode = this.blockA.previousConnection;
|
||||
test('Valid if block - start at top', function () {
|
||||
const startNode = this.blockA;
|
||||
const nextNode = this.cursor.getNextNode(
|
||||
startNode,
|
||||
this.isConnection,
|
||||
this.isBlock,
|
||||
false,
|
||||
);
|
||||
assert.equal(nextNode, this.blockA.nextConnection);
|
||||
assert.equal(nextNode, this.blockB);
|
||||
});
|
||||
test('Valid if connection - start in middle', function () {
|
||||
test('Valid if block - start in middle', function () {
|
||||
const startNode = this.blockB;
|
||||
const nextNode = this.cursor.getNextNode(
|
||||
startNode,
|
||||
this.isConnection,
|
||||
this.isBlock,
|
||||
false,
|
||||
);
|
||||
assert.equal(nextNode, this.blockB.nextConnection);
|
||||
assert.equal(nextNode, this.blockC);
|
||||
});
|
||||
test('Valid if connection - start at end', function () {
|
||||
const startNode = this.blockC.nextConnection;
|
||||
test('Valid if block - start at end', function () {
|
||||
const startNode = this.blockC.getField('FIELD');
|
||||
const nextNode = this.cursor.getNextNode(
|
||||
startNode,
|
||||
this.isConnection,
|
||||
this.isBlock,
|
||||
false,
|
||||
);
|
||||
assert.isNull(nextNode);
|
||||
@@ -583,14 +582,10 @@ suite('Cursor', function () {
|
||||
assert.equal(nextNode, this.blockA.previousConnection);
|
||||
});
|
||||
|
||||
test('Valid if connection - start at end - with loopback', function () {
|
||||
const startNode = this.blockC.nextConnection;
|
||||
const nextNode = this.cursor.getNextNode(
|
||||
startNode,
|
||||
this.isConnection,
|
||||
true,
|
||||
);
|
||||
assert.equal(nextNode, this.blockA.previousConnection);
|
||||
test('Valid if block - start at end - with loopback', function () {
|
||||
const startNode = this.blockC;
|
||||
const nextNode = this.cursor.getNextNode(startNode, this.isBlock, true);
|
||||
assert.equal(nextNode, this.blockA);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -637,8 +632,8 @@ suite('Cursor', function () {
|
||||
this.cursor = this.workspace.getCursor();
|
||||
this.neverValid = () => false;
|
||||
this.alwaysValid = () => true;
|
||||
this.isConnection = (node) => {
|
||||
return node && node instanceof Blockly.RenderedConnection;
|
||||
this.isBlock = (node) => {
|
||||
return node && node instanceof Blockly.BlockSvg;
|
||||
};
|
||||
});
|
||||
teardown(function () {
|
||||
@@ -708,7 +703,7 @@ suite('Cursor', function () {
|
||||
});
|
||||
|
||||
test('Always valid - start at top', function () {
|
||||
const startNode = this.blockA.previousConnection;
|
||||
const startNode = this.blockA;
|
||||
const previousNode = this.cursor.getPreviousNode(
|
||||
startNode,
|
||||
this.alwaysValid,
|
||||
@@ -723,7 +718,7 @@ suite('Cursor', function () {
|
||||
this.alwaysValid,
|
||||
false,
|
||||
);
|
||||
assert.equal(previousNode, this.blockB.previousConnection);
|
||||
assert.equal(previousNode, this.blockA.getField('FIELD'));
|
||||
});
|
||||
test('Always valid - start at end', function () {
|
||||
const startNode = this.blockC.nextConnection;
|
||||
@@ -735,32 +730,32 @@ suite('Cursor', function () {
|
||||
assert.equal(previousNode, this.blockC.getField('FIELD'));
|
||||
});
|
||||
|
||||
test('Valid if connection - start at top', function () {
|
||||
const startNode = this.blockA.previousConnection;
|
||||
test('Valid if block - start at top', function () {
|
||||
const startNode = this.blockA;
|
||||
const previousNode = this.cursor.getPreviousNode(
|
||||
startNode,
|
||||
this.isConnection,
|
||||
this.isBlock,
|
||||
false,
|
||||
);
|
||||
assert.isNull(previousNode);
|
||||
});
|
||||
test('Valid if connection - start in middle', function () {
|
||||
test('Valid if block - start in middle', function () {
|
||||
const startNode = this.blockB;
|
||||
const previousNode = this.cursor.getPreviousNode(
|
||||
startNode,
|
||||
this.isConnection,
|
||||
this.isBlock,
|
||||
false,
|
||||
);
|
||||
assert.equal(previousNode, this.blockB.previousConnection);
|
||||
assert.equal(previousNode, this.blockA);
|
||||
});
|
||||
test('Valid if connection - start at end', function () {
|
||||
const startNode = this.blockC.nextConnection;
|
||||
test('Valid if block - start at end', function () {
|
||||
const startNode = this.blockC;
|
||||
const previousNode = this.cursor.getPreviousNode(
|
||||
startNode,
|
||||
this.isConnection,
|
||||
this.isBlock,
|
||||
false,
|
||||
);
|
||||
assert.equal(previousNode, this.blockC.previousConnection);
|
||||
assert.equal(previousNode, this.blockB);
|
||||
});
|
||||
test('Never valid - start at top - with loopback', function () {
|
||||
const startNode = this.blockA.previousConnection;
|
||||
@@ -780,14 +775,14 @@ suite('Cursor', function () {
|
||||
);
|
||||
assert.equal(previousNode, this.blockC.nextConnection);
|
||||
});
|
||||
test('Valid if connection - start at top - with loopback', function () {
|
||||
const startNode = this.blockA.previousConnection;
|
||||
test('Valid if block - start at top - with loopback', function () {
|
||||
const startNode = this.blockA;
|
||||
const previousNode = this.cursor.getPreviousNode(
|
||||
startNode,
|
||||
this.isConnection,
|
||||
this.isBlock,
|
||||
true,
|
||||
);
|
||||
assert.equal(previousNode, this.blockC.nextConnection);
|
||||
assert.equal(previousNode, this.blockC);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -166,7 +166,7 @@ suite('Navigation', function () {
|
||||
},
|
||||
{
|
||||
'type': 'fields_and_input2',
|
||||
'message0': '%1 %2 %3 hi %4 bye',
|
||||
'message0': '%1 %2 %3 %4 bye',
|
||||
'args0': [
|
||||
{
|
||||
'type': 'input_value',
|
||||
@@ -245,6 +245,7 @@ suite('Navigation', function () {
|
||||
const outputNextBlock = this.workspace.newBlock('output_next');
|
||||
this.blocks.secondBlock = secondBlock;
|
||||
this.blocks.outputNextBlock = outputNextBlock;
|
||||
this.workspace.cleanUp();
|
||||
});
|
||||
suite('Next', function () {
|
||||
setup(function () {
|
||||
@@ -261,12 +262,11 @@ suite('Navigation', function () {
|
||||
const nextNode = this.navigator.getNextSibling(prevConnection);
|
||||
assert.equal(nextNode, this.blocks.statementInput1);
|
||||
});
|
||||
test('fromBlockToNext', function () {
|
||||
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||
test('fromBlockToNextBlock', function () {
|
||||
const nextNode = this.navigator.getNextSibling(
|
||||
this.blocks.statementInput1,
|
||||
);
|
||||
assert.equal(nextNode, nextConnection);
|
||||
assert.equal(nextNode, this.blocks.statementInput2);
|
||||
});
|
||||
test('fromNextToPrevious', function () {
|
||||
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||
@@ -304,12 +304,12 @@ suite('Navigation', function () {
|
||||
const nextNode = this.navigator.getNextSibling(output);
|
||||
assert.equal(nextNode, this.blocks.fieldWithOutput);
|
||||
});
|
||||
test('fromFieldToInput', function () {
|
||||
test('fromFieldToNestedBlock', function () {
|
||||
const field = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
||||
const inputConnection =
|
||||
this.blocks.statementInput1.inputList[0].connection;
|
||||
const nextNode = this.navigator.getNextSibling(field);
|
||||
assert.equal(nextNode, inputConnection);
|
||||
assert.equal(nextNode, this.blocks.fieldWithOutput);
|
||||
});
|
||||
test('fromFieldToField', function () {
|
||||
const field = this.blocks.fieldAndInputs.inputList[0].fieldRow[0];
|
||||
@@ -338,17 +338,17 @@ suite('Navigation', function () {
|
||||
});
|
||||
test('fromBlockToPrevious', function () {
|
||||
const prevNode = this.navigator.getPreviousSibling(
|
||||
this.blocks.statementInput1,
|
||||
this.blocks.statementInput2,
|
||||
);
|
||||
const prevConnection = this.blocks.statementInput1.previousConnection;
|
||||
assert.equal(prevNode, prevConnection);
|
||||
const previousBlock = this.blocks.statementInput1;
|
||||
assert.equal(prevNode, previousBlock);
|
||||
});
|
||||
test('fromBlockToOutput', function () {
|
||||
test('fromOutputBlockToPreviousField', function () {
|
||||
const prevNode = this.navigator.getPreviousSibling(
|
||||
this.blocks.fieldWithOutput,
|
||||
);
|
||||
const outputConnection = this.blocks.fieldWithOutput.outputConnection;
|
||||
assert.equal(prevNode, outputConnection);
|
||||
assert.equal(prevNode, [...this.blocks.statementInput1.getFields()][1]);
|
||||
});
|
||||
test('fromNextToBlock', function () {
|
||||
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||
@@ -383,11 +383,16 @@ suite('Navigation', function () {
|
||||
assert.isNull(prevNode);
|
||||
});
|
||||
test('fromFieldToInput', function () {
|
||||
const outputBlock = this.workspace.newBlock('field_input');
|
||||
this.blocks.fieldAndInputs2.inputList[0].connection.connect(
|
||||
outputBlock.outputConnection,
|
||||
);
|
||||
|
||||
const field = this.blocks.fieldAndInputs2.inputList[1].fieldRow[0];
|
||||
const inputConnection =
|
||||
this.blocks.fieldAndInputs2.inputList[0].connection;
|
||||
const prevNode = this.navigator.getPreviousSibling(field);
|
||||
assert.equal(prevNode, inputConnection);
|
||||
assert.equal(prevNode, outputBlock);
|
||||
});
|
||||
test('fromFieldToField', function () {
|
||||
const field = this.blocks.fieldAndInputs.inputList[1].fieldRow[0];
|
||||
@@ -423,10 +428,10 @@ suite('Navigation', function () {
|
||||
const inNode = this.navigator.getFirstChild(input.connection);
|
||||
assert.equal(inNode, previousConnection);
|
||||
});
|
||||
test('fromBlockToInput', function () {
|
||||
const input = this.blocks.valueInput.inputList[0];
|
||||
test('fromBlockToField', function () {
|
||||
const field = this.blocks.valueInput.getField('NAME');
|
||||
const inNode = this.navigator.getFirstChild(this.blocks.valueInput);
|
||||
assert.equal(inNode, input.connection);
|
||||
assert.equal(inNode, field);
|
||||
});
|
||||
test('fromBlockToField', function () {
|
||||
const inNode = this.navigator.getFirstChild(
|
||||
@@ -440,12 +445,10 @@ suite('Navigation', function () {
|
||||
assert.isNull(inNode);
|
||||
});
|
||||
test('fromBlockToInput_DummyInputValue', function () {
|
||||
const inputConnection =
|
||||
this.blocks.dummyInputValue.inputList[1].connection;
|
||||
const inNode = this.navigator.getFirstChild(
|
||||
this.blocks.dummyInputValue,
|
||||
);
|
||||
assert.equal(inNode, inputConnection);
|
||||
assert.equal(inNode, null);
|
||||
});
|
||||
test('fromOuputToNull', function () {
|
||||
const output = this.blocks.fieldWithOutput.outputConnection;
|
||||
@@ -540,25 +543,25 @@ suite('Navigation', function () {
|
||||
const outNode = this.navigator.getParent(next);
|
||||
assert.equal(outNode, this.blocks.secondBlock.inputList[0].connection);
|
||||
});
|
||||
test('fromBlockToStack', function () {
|
||||
test('fromBlockToWorkspace', function () {
|
||||
const outNode = this.navigator.getParent(this.blocks.statementInput2);
|
||||
assert.equal(outNode, this.blocks.statementInput1);
|
||||
assert.equal(outNode, this.workspace);
|
||||
});
|
||||
test('fromBlockToInput', function () {
|
||||
const input = this.blocks.statementInput2.inputList[1].connection;
|
||||
test('fromBlockToEnclosingStatement', function () {
|
||||
const enclosingStatement = this.blocks.statementInput2;
|
||||
const outNode = this.navigator.getParent(this.blocks.statementInput3);
|
||||
assert.equal(outNode, input);
|
||||
assert.equal(outNode, enclosingStatement);
|
||||
});
|
||||
test('fromTopBlockToStack', function () {
|
||||
test('fromTopBlockToWorkspace', function () {
|
||||
const outNode = this.navigator.getParent(this.blocks.statementInput1);
|
||||
assert.equal(outNode, this.blocks.statementInput1);
|
||||
assert.equal(outNode, this.workspace);
|
||||
});
|
||||
test('fromBlockToStack_OutputConnection', function () {
|
||||
test('fromOutputBlockToWorkspace', function () {
|
||||
const outNode = this.navigator.getParent(this.blocks.fieldWithOutput2);
|
||||
assert.equal(outNode, this.blocks.fieldWithOutput2);
|
||||
assert.equal(outNode, this.workspace);
|
||||
});
|
||||
test('fromBlockToInput_OutputConnection', function () {
|
||||
const inputConnection = this.blocks.secondBlock.inputList[0].connection;
|
||||
test('fromOutputNextBlockToWorkspace', function () {
|
||||
const inputConnection = this.blocks.secondBlock;
|
||||
const outNode = this.navigator.getParent(this.blocks.outputNextBlock);
|
||||
assert.equal(outNode, inputConnection);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user