diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 158407d7a..54778818f 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -313,8 +313,8 @@ Blockly.ASTNode.prototype.findNextForField_ = function() { var block = location.getSourceBlock(); var curIdx = block.inputList.indexOf(input); var fieldIdx = input.fieldRow.indexOf(location) + 1; - for (var i = curIdx, input; input = block.inputList[i]; i++) { - var fieldRow = input.fieldRow; + for (var i = curIdx, newInput; newInput = block.inputList[i]; i++) { + var fieldRow = newInput.fieldRow; while (fieldIdx < fieldRow.length) { if (fieldRow[fieldIdx].EDITABLE) { return Blockly.ASTNode.createFieldNode(fieldRow[fieldIdx]); @@ -322,8 +322,8 @@ Blockly.ASTNode.prototype.findNextForField_ = function() { fieldIdx++; } fieldIdx = 0; - if (input.connection) { - return Blockly.ASTNode.createInputNode(input); + if (newInput.connection) { + return Blockly.ASTNode.createInputNode(newInput); } } return null; @@ -438,12 +438,15 @@ Blockly.ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { /** * Get the AST node pointing to the input that the block is nested under or if * the block is not nested then get the stack AST node. - * @param {!Blockly.Block} block The source block of the current location. + * @param {Blockly.Block} block The source block of the current location. * @return {Blockly.ASTNode} The AST node pointing to the input connection or * the top block of the stack this block is in. * @private */ Blockly.ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { + if (!block) { + return null; + } var topBlock = null; // If the block doesn't have a previous connection then it is the top of the // substack. @@ -467,7 +470,7 @@ Blockly.ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { /** * Find the first editable field or input with a connection on a given block. - * @param {!Blockly.BlockSvg} block The source block of the current location. + * @param {!Blockly.Block} block The source block of the current location. * @return {Blockly.ASTNode} An AST node pointing to the first field or input. * Null if there are no editable fields or inputs with connections on the block. * @private @@ -568,6 +571,7 @@ Blockly.ASTNode.prototype.in = function() { return this.findTopASTNodeForBlock_(block); case Blockly.ASTNode.types.BLOCK: + var block = /** @type {!Blockly.Block} */ (this.location_); return this.findFirstFieldOrInput_(this.location_); case Blockly.ASTNode.types.INPUT: diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index 9bfd4a4a6..5b1e1d3ce 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -184,7 +184,7 @@ Blockly.Cursor.prototype.out = function() { } var newNode = curNode.out(); - if (newNode.getType() === Blockly.ASTNode.types.BLOCK) { + if (newNode && newNode.getType() === Blockly.ASTNode.types.BLOCK) { newNode = newNode.prev(); } diff --git a/core/keyboard_nav/cursor_svg.js b/core/keyboard_nav/cursor_svg.js index 1bf28459c..efddcfd16 100644 --- a/core/keyboard_nav/cursor_svg.js +++ b/core/keyboard_nav/cursor_svg.js @@ -347,9 +347,9 @@ Blockly.CursorSvg.prototype.showCurrent_ = function() { /** * Position the cursor for a block. * Displays an outline of the top half of a rectangle around a block. - * @param {!number} width The width of the block. - * @param {!number} cursorOffset The extra padding for around the block. - * @param {!number} cursorHeight The height of the cursor. + * @param {number} width The width of the block. + * @param {number} cursorOffset The extra padding for around the block. + * @param {number} cursorHeight The height of the cursor. */ Blockly.CursorSvg.prototype.positionBlock_ = function(width, cursorOffset, cursorHeight) { var cursorPath = Blockly.utils.svgPaths.moveBy(-1 * cursorOffset, cursorHeight) + @@ -377,9 +377,9 @@ Blockly.CursorSvg.prototype.positionInput_ = function(connection) { /** * Move and show the cursor at the specified coordinate in workspace units. * Displays a horizontal line. - * @param {!number} x The new x, in workspace units. - * @param {!number} y The new y, in workspace units. - * @param {!number} width The new width, in workspace units. + * @param {number} x The new x, in workspace units. + * @param {number} y The new y, in workspace units. + * @param {number} width The new width, in workspace units. * @private */ Blockly.CursorSvg.prototype.positionLine_ = function(x, y, width) { @@ -391,8 +391,8 @@ Blockly.CursorSvg.prototype.positionLine_ = function(x, y, width) { /** * Position the cursor for an output connection. * Displays a puzzle outline and the top and bottom path. - * @param {!number} width The width of the block. - * @param {!number} height The height of the block. + * @param {number} width The width of the block. + * @param {number} height The height of the block. * @private */ Blockly.CursorSvg.prototype.positionOutput_ = function(width, height) { @@ -409,9 +409,9 @@ Blockly.CursorSvg.prototype.positionOutput_ = function(width, height) { * Position the cursor for a previous connection. * Displays a half rectangle with a notch in the top to represent the previous * conenction. - * @param {!number} width The width of the block. - * @param {!number} cursorOffset The offset of the cursor from around the block. - * @param {!number} cursorHeight The height of the cursor. + * @param {number} width The width of the block. + * @param {number} cursorOffset The offset of the cursor from around the block. + * @param {number} cursorHeight The height of the cursor. * @private */ Blockly.CursorSvg.prototype.positionPrevious_ = function(width, cursorOffset, cursorHeight) { @@ -428,10 +428,10 @@ Blockly.CursorSvg.prototype.positionPrevious_ = function(width, cursorOffset, cu /** * Move and show the cursor at the specified coordinate in workspace units. * Displays a filled in rectangle. - * @param {!number} x The new x, in workspace units. - * @param {!number} y The new y, in workspace units. - * @param {!number} width The new width, in workspace units. - * @param {!number} height The new height, in workspace units. + * @param {number} x The new x, in workspace units. + * @param {number} y The new y, in workspace units. + * @param {number} width The new width, in workspace units. + * @param {number} height The new height, in workspace units. * @private */ Blockly.CursorSvg.prototype.positionRect_ = function(x, y, width, height) { @@ -459,8 +459,10 @@ Blockly.CursorSvg.prototype.hide = function() { */ Blockly.CursorSvg.prototype.draw = function(curNode) { if (!curNode) { + this.hide(); return; } + if (curNode.getType() === Blockly.ASTNode.types.BLOCK) { var block = /** @type {Blockly.BlockSvg} */ (curNode.getLocation()); this.showWithBlockPrevOutput_(block); diff --git a/core/keyboard_nav/flyout_cursor.js b/core/keyboard_nav/flyout_cursor.js index a9e62ea35..428dce97c 100644 --- a/core/keyboard_nav/flyout_cursor.js +++ b/core/keyboard_nav/flyout_cursor.js @@ -49,18 +49,16 @@ Blockly.utils.object.inherits(Blockly.FlyoutCursor, Blockly.Cursor); * @override */ Blockly.FlyoutCursor.prototype.next = function() { - if (!this.isMarker_) { - var curNode = this.getCurNode(); - if (!curNode) { - return null; - } - var newNode = curNode.next(); - - if (newNode) { - this.setLocation(newNode); - } - return newNode; + var curNode = this.getCurNode(); + if (!curNode) { + return null; } + var newNode = curNode.next(); + + if (newNode) { + this.setLocation(newNode); + } + return newNode; }; /** @@ -79,18 +77,16 @@ Blockly.FlyoutCursor.prototype.in = function() { * @override */ Blockly.FlyoutCursor.prototype.prev = function() { - if (!this.isMarker_) { - var curNode = this.getCurNode(); - if (!curNode) { - return null; - } - var newNode = curNode.prev(); - - if (newNode) { - this.setLocation(newNode); - } - return newNode; + var curNode = this.getCurNode(); + if (!curNode) { + return null; } + var newNode = curNode.prev(); + + if (newNode) { + this.setLocation(newNode); + } + return newNode; }; /** diff --git a/core/keyboard_nav/key_map.js b/core/keyboard_nav/key_map.js index c53d02291..12c90cdba 100644 --- a/core/keyboard_nav/key_map.js +++ b/core/keyboard_nav/key_map.js @@ -99,7 +99,7 @@ Blockly.user.keyMap.getActionByKeyCode = function(keyCode) { * Get the serialized key that corresponds to the action. * @param {!Blockly.Action} action The action for which we want to get * the key. - * @return {string} The serialized key or null if the action does not have + * @return {?string} The serialized key or null if the action does not have * a key mapping. * @package */ diff --git a/core/keyboard_nav/navigation.js b/core/keyboard_nav/navigation.js index 429c99cdc..5c724b3ab 100644 --- a/core/keyboard_nav/navigation.js +++ b/core/keyboard_nav/navigation.js @@ -264,7 +264,7 @@ Blockly.navigation.focusFlyout_ = function() { } if (flyout && flyout.getWorkspace()) { - var topBlocks = flyout.getWorkspace().getTopBlocks(); + var topBlocks = flyout.getWorkspace().getTopBlocks(true); if (topBlocks.length > 0) { topBlock = topBlocks[0]; var astNode = Blockly.ASTNode.createStackNode(topBlock); @@ -665,7 +665,7 @@ Blockly.navigation.focusWorkspace_ = function() { Blockly.hideChaff(); var cursor = Blockly.getMainWorkspace().getCursor(); var reset = Blockly.getMainWorkspace().getToolbox() ? true : false; - var topBlocks = Blockly.getMainWorkspace().getTopBlocks(); + var topBlocks = Blockly.getMainWorkspace().getTopBlocks(true); Blockly.navigation.resetFlyout_(reset); Blockly.navigation.currentState_ = Blockly.navigation.STATE_WS; @@ -717,9 +717,9 @@ Blockly.navigation.getSourceBlock_ = function(node) { return null; } if (node.getType() === Blockly.ASTNode.types.BLOCK) { - return node.getLocation(); + return /** @type {Blockly.Block} */ (node.getLocation()); } else if (node.getType() === Blockly.ASTNode.types.STACK) { - return node.getLocation(); + return /** @type {Blockly.Block} */ (node.getLocation()); } else if (node.getType() === Blockly.ASTNode.types.WORKSPACE) { return null; } else { @@ -756,7 +756,7 @@ Blockly.navigation.moveCursorOnBlockDelete = function(deletedBlock) { } // If the cursor is on a block whose parent is being deleted, move the // cursor to the workspace. - } else if (deletedBlock.getChildren().indexOf(block) > -1) { + } else if (deletedBlock.getChildren(false).indexOf(block) > -1) { cursor.setLocation(Blockly.ASTNode.createWorkspaceNode(block.workspace, block.getRelativeToSurfaceXY())); }