From 468b673b73f5b3841cfe943e0238b1e118ea193e Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 27 Sep 2019 14:34:28 -0700 Subject: [PATCH] Fix bugs (#3108) * Fix various bugs around keyboard nav --- core/keyboard_nav/cursor.js | 4 ---- core/keyboard_nav/navigation.js | 8 +++++++- core/toolbox.js | 3 ++- demos/keyboard_nav/basic_cursor.js | 6 +++--- tests/mocha/cursor_test.js | 28 +++++++++++++++++++--------- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index dbbbe53fa..2337cb396 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -138,10 +138,6 @@ Blockly.Cursor.prototype.in = function() { } var newNode = curNode.in(); - if (newNode && newNode.getType() == Blockly.ASTNode.types.OUTPUT) { - newNode = newNode.next() || newNode; - } - if (newNode) { this.setCurNode(newNode); } diff --git a/core/keyboard_nav/navigation.js b/core/keyboard_nav/navigation.js index 6af2adade..11e6f9503 100644 --- a/core/keyboard_nav/navigation.js +++ b/core/keyboard_nav/navigation.js @@ -498,11 +498,17 @@ Blockly.navigation.insertBlock = function(block, destConnection) { case Blockly.OUTPUT_VALUE: for (var i = 0; i < block.inputList.length; i++) { var inputConnection = block.inputList[i].connection; - if (inputConnection.type === Blockly.INPUT_VALUE && + if (inputConnection && inputConnection.type === Blockly.INPUT_VALUE && Blockly.navigation.connect_(inputConnection, destConnection)) { return true; } } + // If there are no input values pass the output and destination connections + // to connect_ to find a way to connect the two. + if (block.outputConnection && + Blockly.navigation.connect_(block.outputConnection, destConnection)) { + return true; + } break; } Blockly.navigation.warn_('This block can not be inserted at the marked location.'); diff --git a/core/toolbox.js b/core/toolbox.js index c5899212f..5a7cbaa7d 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -296,7 +296,8 @@ Blockly.Toolbox.prototype.handleAfterTreeSelected_ = function( } else { // Hide the flyout. this.flyout_.hide(); - if (Blockly.keyboardAccessibilityMode) { + if (Blockly.keyboardAccessibilityMode && + !(newNode instanceof Blockly.Toolbox.TreeSeparator)) { Blockly.navigation.setState(Blockly.navigation.STATE_WS); } } diff --git a/demos/keyboard_nav/basic_cursor.js b/demos/keyboard_nav/basic_cursor.js index ddbf5c3ea..30b09c83e 100644 --- a/demos/keyboard_nav/basic_cursor.js +++ b/demos/keyboard_nav/basic_cursor.js @@ -52,7 +52,8 @@ Blockly.BasicCursor.prototype.validNode_ = function(node) { type == Blockly.ASTNode.types.INPUT || type == Blockly.ASTNode.types.FIELD || type == Blockly.ASTNode.types.NEXT || - type == Blockly.ASTNode.types.PREVIOUS) { + type == Blockly.ASTNode.types.PREVIOUS || + type == Blockly.ASTNode.types.WORKSPACE) { isValid = true; } return isValid; @@ -97,8 +98,7 @@ Blockly.BasicCursor.prototype.getNextNode_ = function(node) { var siblingOrParent = this.findSiblingOrParent_(node.out()); if (this.validNode_(siblingOrParent)) { return siblingOrParent; - } else if (siblingOrParent && - siblingOrParent.getType() !== Blockly.ASTNode.types.WORKSPACE) { + } else if (siblingOrParent) { return this.getNextNode_(siblingOrParent); } return null; diff --git a/tests/mocha/cursor_test.js b/tests/mocha/cursor_test.js index f574310cf..e0fede85c 100644 --- a/tests/mocha/cursor_test.js +++ b/tests/mocha/cursor_test.js @@ -73,27 +73,28 @@ suite('Cursor', function() { this.workspace.dispose(); }); - test('Next - From a block skip over next connection', function() { - var blockNode = Blockly.ASTNode.createBlockNode(this.blocks.A); - this.cursor.setCurNode(blockNode); + test('Next - From a Previous skip over next connection and block', function() { + var prevNode = Blockly.ASTNode.createConnectionNode(this.blocks.A.previousConnection); + this.cursor.setCurNode(prevNode); this.cursor.next(); var curNode = this.cursor.getCurNode(); assertEquals(curNode.getLocation(), this.blocks.B.previousConnection); }); test('Next - From last block in a stack go to next connection', function() { - var blockNode = Blockly.ASTNode.createBlockNode(this.blocks.B); - this.cursor.setCurNode(blockNode); + var prevNode = Blockly.ASTNode.createConnectionNode(this.blocks.B.previousConnection); + this.cursor.setCurNode(prevNode); this.cursor.next(); var curNode = this.cursor.getCurNode(); assertEquals(curNode.getLocation(), this.blocks.B.nextConnection); }); - test('In - From input skip over output connection', function() { - var inputNode = Blockly.ASTNode.createInputNode(this.blocks.A.inputList[0]); - this.cursor.setCurNode(inputNode); + test('In - From output connection', function() { + var fieldBlock = this.blocks.E; + var outputNode = Blockly.ASTNode.createConnectionNode(fieldBlock.outputConnection); + this.cursor.setCurNode(outputNode); this.cursor.in(); var curNode = this.cursor.getCurNode(); - assertEquals(curNode.getLocation(), this.blocks.E); + assertEquals(curNode.getLocation(), fieldBlock.inputList[0].fieldRow[0]); }); test('Prev - From previous connection skip over next connection', function() { @@ -104,4 +105,13 @@ suite('Cursor', function() { var curNode = this.cursor.getCurNode(); assertEquals(curNode.getLocation(), this.blocks.A.previousConnection); }); + + test('Out - From field skip over block node', function() { + var field = this.blocks.E.inputList[0].fieldRow[0]; + var fieldNode = Blockly.ASTNode.createFieldNode(field); + this.cursor.setCurNode(fieldNode); + this.cursor.out(); + var curNode = this.cursor.getCurNode(); + assertEquals(curNode.getLocation(), this.blocks.E.outputConnection); + }); });