mirror of
https://github.com/google/blockly.git
synced 2026-01-23 08:40:10 +01:00
fix: Skip invisible inputs in the field navigation policy (#9092)
* Skip over hidden inputs when navigating from a field * Add tests and fix implementation
This commit is contained in:
@@ -48,12 +48,14 @@ export class FieldNavigationPolicy implements INavigationPolicy<Field<any>> {
|
||||
let fieldIdx = input.fieldRow.indexOf(current) + 1;
|
||||
for (let i = curIdx; i < block.inputList.length; i++) {
|
||||
const newInput = block.inputList[i];
|
||||
const fieldRow = newInput.fieldRow;
|
||||
if (fieldIdx < fieldRow.length) return fieldRow[fieldIdx];
|
||||
fieldIdx = 0;
|
||||
if (newInput.connection?.targetBlock()) {
|
||||
return newInput.connection.targetBlock() as BlockSvg;
|
||||
if (newInput.isVisible()) {
|
||||
const fieldRow = newInput.fieldRow;
|
||||
if (fieldIdx < fieldRow.length) return fieldRow[fieldIdx];
|
||||
if (newInput.connection?.targetBlock()) {
|
||||
return newInput.connection.targetBlock() as BlockSvg;
|
||||
}
|
||||
}
|
||||
fieldIdx = 0;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -73,12 +75,13 @@ export class FieldNavigationPolicy implements INavigationPolicy<Field<any>> {
|
||||
let fieldIdx = parentInput.fieldRow.indexOf(current) - 1;
|
||||
for (let i = curIdx; i >= 0; i--) {
|
||||
const input = block.inputList[i];
|
||||
if (input.connection?.targetBlock() && input !== parentInput) {
|
||||
return input.connection.targetBlock() as BlockSvg;
|
||||
if (input.isVisible()) {
|
||||
if (input.connection?.targetBlock() && input !== parentInput) {
|
||||
return input.connection.targetBlock() as BlockSvg;
|
||||
}
|
||||
const fieldRow = input.fieldRow;
|
||||
if (fieldIdx > -1) return fieldRow[fieldIdx];
|
||||
}
|
||||
const fieldRow = input.fieldRow;
|
||||
if (fieldIdx > -1) return fieldRow[fieldIdx];
|
||||
|
||||
// Reset the fieldIdx to the length of the field row of the previous
|
||||
// input.
|
||||
if (i - 1 >= 0) {
|
||||
|
||||
@@ -534,6 +534,13 @@ suite('Navigation', function () {
|
||||
const nextNode = this.navigator.getNextSibling(this.blocks.buttonBlock);
|
||||
assert.equal(nextNode.id, this.blocks.buttonNext.id);
|
||||
});
|
||||
test('fromFieldSkipsHiddenInputs', function () {
|
||||
this.blocks.buttonBlock.inputList[2].setVisible(false);
|
||||
const fieldStart = this.blocks.buttonBlock.getField('BUTTON2');
|
||||
const fieldEnd = this.blocks.buttonBlock.getField('BUTTON3');
|
||||
const nextNode = this.navigator.getNextSibling(fieldStart);
|
||||
assert.equal(nextNode.name, fieldEnd.name);
|
||||
});
|
||||
});
|
||||
|
||||
suite('Previous', function () {
|
||||
@@ -669,6 +676,13 @@ suite('Navigation', function () {
|
||||
);
|
||||
assert.equal(prevNode.id, this.blocks.buttonBlock.id);
|
||||
});
|
||||
test('fromFieldSkipsHiddenInputs', function () {
|
||||
this.blocks.buttonBlock.inputList[2].setVisible(false);
|
||||
const fieldStart = this.blocks.buttonBlock.getField('BUTTON3');
|
||||
const fieldEnd = this.blocks.buttonBlock.getField('BUTTON2');
|
||||
const nextNode = this.navigator.getPreviousSibling(fieldStart);
|
||||
assert.equal(nextNode.name, fieldEnd.name);
|
||||
});
|
||||
});
|
||||
|
||||
suite('In', function () {
|
||||
|
||||
Reference in New Issue
Block a user