Skip to content

Commit cc9384a

Browse files
authored
fix: Don't visit collapsed blocks (#9090)
* WIP on line by line navigation Doesn't work, likely due to isValid check. * Add all inputs to the list of siblings * Fix formatting * Add tests * Remove dupe keys * fix: Make blocks with display: none not focusable * Undo changes to canBeFocused * Don't traverse inputs that are invisible
1 parent 056aaf3 commit cc9384a

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

core/keyboard_nav/block_navigation_policy.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export class BlockNavigationPolicy implements INavigationPolicy<BlockSvg> {
2525
if (icons.length) return icons[0];
2626

2727
for (const input of current.inputList) {
28+
if (!input.isVisible()) {
29+
continue;
30+
}
2831
for (const field of input.fieldRow) {
2932
return field;
3033
}
@@ -70,6 +73,9 @@ export class BlockNavigationPolicy implements INavigationPolicy<BlockSvg> {
7073
let siblings: (BlockSvg | Field)[] = [];
7174
if (parent instanceof BlockSvg) {
7275
for (let i = 0, input; (input = parent.inputList[i]); i++) {
76+
if (!input.isVisible()) {
77+
continue;
78+
}
7379
siblings.push(...input.fieldRow);
7480
const child = input.connection?.targetBlock();
7581
if (child) {
@@ -112,6 +118,9 @@ export class BlockNavigationPolicy implements INavigationPolicy<BlockSvg> {
112118
let siblings: (BlockSvg | Field)[] = [];
113119
if (parent instanceof BlockSvg) {
114120
for (let i = 0, input; (input = parent.inputList[i]); i++) {
121+
if (!input.isVisible()) {
122+
continue;
123+
}
115124
siblings.push(...input.fieldRow);
116125
const child = input.connection?.targetBlock();
117126
if (child) {

tests/mocha/navigation_test.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,26 @@ suite('Navigation', function () {
369369
this.blocks.secondBlock = secondBlock;
370370
this.blocks.outputNextBlock = outputNextBlock;
371371

372-
const buttonBlock = this.workspace.newBlock('buttons');
373-
const buttonInput1 = this.workspace.newBlock('field_input');
374-
const buttonInput2 = this.workspace.newBlock('field_input');
372+
const buttonBlock = this.workspace.newBlock('buttons', 'button_block');
373+
const buttonInput1 = this.workspace.newBlock(
374+
'field_input',
375+
'button_input1',
376+
);
377+
const buttonInput2 = this.workspace.newBlock(
378+
'field_input',
379+
'button_input2',
380+
);
381+
const buttonNext = this.workspace.newBlock(
382+
'input_statement',
383+
'button_next',
384+
);
375385
buttonBlock.inputList[0].connection.connect(
376386
buttonInput1.outputConnection,
377387
);
378388
buttonBlock.inputList[2].connection.connect(
379389
buttonInput2.outputConnection,
380390
);
391+
buttonBlock.nextConnection.connect(buttonNext.previousConnection);
381392
// Make buttons by adding a click handler
382393
const clickHandler = function () {
383394
return;
@@ -388,6 +399,7 @@ suite('Navigation', function () {
388399
this.blocks.buttonBlock = buttonBlock;
389400
this.blocks.buttonInput1 = buttonInput1;
390401
this.blocks.buttonInput2 = buttonInput2;
402+
this.blocks.buttonNext = buttonNext;
391403

392404
this.workspace.cleanUp();
393405
});
@@ -505,17 +517,22 @@ suite('Navigation', function () {
505517
});
506518
test('fromBlockToFieldInNextInput', function () {
507519
const field = this.blocks.buttonBlock.getField('BUTTON2');
508-
const prevNode = this.navigator.getNextSibling(
520+
const nextNode = this.navigator.getNextSibling(
509521
this.blocks.buttonInput1,
510522
);
511-
assert.equal(prevNode, field);
523+
assert.equal(nextNode, field);
512524
});
513525
test('fromBlockToFieldSkippingInput', function () {
514526
const field = this.blocks.buttonBlock.getField('BUTTON3');
515-
const prevNode = this.navigator.getNextSibling(
527+
const nextNode = this.navigator.getNextSibling(
516528
this.blocks.buttonInput2,
517529
);
518-
assert.equal(prevNode, field);
530+
assert.equal(nextNode, field);
531+
});
532+
test('skipsChildrenOfCollapsedBlocks', function () {
533+
this.blocks.buttonBlock.setCollapsed(true);
534+
const nextNode = this.navigator.getNextSibling(this.blocks.buttonBlock);
535+
assert.equal(nextNode.id, this.blocks.buttonNext.id);
519536
});
520537
});
521538

@@ -645,6 +662,13 @@ suite('Navigation', function () {
645662
);
646663
assert.equal(prevNode, field);
647664
});
665+
test('skipsChildrenOfCollapsedBlocks', function () {
666+
this.blocks.buttonBlock.setCollapsed(true);
667+
const prevNode = this.navigator.getPreviousSibling(
668+
this.blocks.buttonNext,
669+
);
670+
assert.equal(prevNode.id, this.blocks.buttonBlock.id);
671+
});
648672
});
649673

650674
suite('In', function () {
@@ -725,6 +749,11 @@ suite('Navigation', function () {
725749
const inNode = this.navigator.getFirstChild(icons[0]);
726750
assert.isNull(inNode);
727751
});
752+
test('skipsChildrenOfCollapsedBlocks', function () {
753+
this.blocks.buttonBlock.setCollapsed(true);
754+
const inNode = this.navigator.getFirstChild(this.blocks.buttonBlock);
755+
assert.isNull(inNode);
756+
});
728757
});
729758

730759
suite('Out', function () {

0 commit comments

Comments
 (0)