diff --git a/src/line_cursor.ts b/src/line_cursor.ts index 0f1bd406..0a458adc 100644 --- a/src/line_cursor.ts +++ b/src/line_cursor.ts @@ -277,134 +277,6 @@ export class LineCursor extends Marker { ); } - /** - * Moves the cursor to the next sibling that is at the same level - * of nesting. - * - * @returns The next sibling node, or null if the current node - * is not set or there is no next sibling node. - */ - nextSibling(): ASTNode | null { - const curNode = this.getCurNode(); - if (!curNode) { - return null; - } - let newNode = null; - switch (curNode.getType()) { - case ASTNode.types.STACK: { - // TODO: Make navigateBetweenStacks public - newNode = (curNode as any).navigateBetweenStacks(true); - break; - } - case ASTNode.types.WORKSPACE: { - break; - } - default: { - const block = curNode.getSourceBlock(); - const nextBlock = block?.getNextBlock(); - if (nextBlock) { - newNode = ASTNode.createBlockNode(nextBlock); - } - break; - } - } - - if (newNode) { - this.setCurNode(newNode); - } - return newNode; - } - - /** - * Moves the cursor to the previous sibling that is at the same level - * of nesting. - * - * @returns The previous sibling node, or null if the current node - * is not set or there is no previous sibling node. - */ - previousSibling(): ASTNode | null { - const curNode = this.getCurNode(); - if (!curNode) { - return null; - } - let newNode = null; - switch (curNode.getType()) { - case ASTNode.types.STACK: { - // TODO: Make navigateBetweenStacks public. - newNode = (curNode as any).navigateBetweenStacks(false); - break; - } - case ASTNode.types.WORKSPACE: { - break; - } - default: { - const block = curNode.getSourceBlock(); - // TODO: Decide what this should do if the source block is - // the first block inside a statement input. - // TODO: Decide what this should do if the source block - // has an output instead of a previous. - const prevBlock = block?.getPreviousBlock(); - if (prevBlock) { - newNode = ASTNode.createBlockNode(prevBlock); - } - break; - } - } - - if (newNode) { - this.setCurNode(newNode); - } - return newNode; - } - - /** - * Moves the cursor out by one level of nesting. - * - * @returns The new node the cursor points to, or null if - * one could not be found. - */ - contextOut(): ASTNode | null { - const curNode = this.getCurNode(); - if (!curNode) { - return null; - } - - // Returns null at the workspace level. - // TODO: Decide where the cursor goes from the workspace level. - const newNode = curNode.out(); - if (newNode) { - this.setCurNode(newNode); - } - return newNode; - } - - /** - * Moves the cursor in by one level of nesting. - * - * @returns The new node the cursor points to, or null if - * one could not be found. - */ - contextIn(): ASTNode | null { - let curNode: ASTNode | null = this.getCurNode(); - if (!curNode) { - return null; - } - // If we are on a previous or output connection, go to the block level - // before performing next operation. - if ( - curNode.getType() === ASTNode.types.PREVIOUS || - curNode.getType() === ASTNode.types.OUTPUT - ) { - curNode = curNode.next(); - } - const newNode = curNode?.in() ?? null; - - if (newNode) { - this.setCurNode(newNode); - } - return newNode; - } - /** * Uses pre order traversal to navigate the Blockly AST. This will allow * a user to easily navigate the entire Blockly AST without having to go in diff --git a/src/navigation_controller.ts b/src/navigation_controller.ts index 724799c3..aaa110b6 100644 --- a/src/navigation_controller.ts +++ b/src/navigation_controller.ts @@ -546,115 +546,6 @@ export class NavigationController { }, keyCodes: [KeyCodes.A], }, - - /** Go to the next sibling of the cursor's current location. */ - nextSibling: { - name: Constants.SHORTCUT_NAMES.GO_TO_NEXT_SIBLING, - preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace), - // Jump to the next node at the same level, when in the workspace. - callback: (workspace, e, shortcut) => { - const cursor = workspace.getCursor() as LineCursor; - - if (this.navigation.getState(workspace) === Constants.STATE.WORKSPACE) { - if (this.fieldShortcutHandler(workspace, shortcut)) { - this.announcer.setText('next sibling (handled by field)'); - return true; - } - if (cursor.nextSibling()) { - this.announcer.setText('next sibling (success)'); - return true; - } - } - this.announcer.setText('next sibling (no-op)'); - return false; - }, - keyCodes: [KeyCodes.N], - }, - - /** Go to the previous sibling of the cursor's current location. */ - previousSibling: { - name: Constants.SHORTCUT_NAMES.GO_TO_PREVIOUS_SIBLING, - preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace), - // Jump to the previous node at the same level, when in the workspace. - callback: (workspace, e, shortcut) => { - const cursor = workspace.getCursor() as LineCursor; - - if (this.navigation.getState(workspace) === Constants.STATE.WORKSPACE) { - if (this.fieldShortcutHandler(workspace, shortcut)) { - this.announcer.setText('previous sibling (handled by field)'); - return true; - } - if (cursor.previousSibling()) { - this.announcer.setText('previous sibling (success)'); - return true; - } - } - this.announcer.setText('previous sibling (no-op)'); - return false; - }, - keyCodes: [KeyCodes.M], - }, - - /** Jump to the root of the current stack. */ - jumpToRoot: { - name: Constants.SHORTCUT_NAMES.JUMP_TO_ROOT, - preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace), - // Jump to the root of the current stack. - callback: (workspace) => { - const cursor = workspace.getCursor(); - if (!cursor) return false; - const curNode = cursor.getCurNode(); - const curBlock = curNode.getSourceBlock(); - if (curBlock) { - const rootBlock = curBlock.getRootBlock(); - const stackNode = ASTNode.createStackNode(rootBlock) as ASTNode; - cursor.setCurNode(stackNode); - this.announcer.setText('jumped to root'); - return true; - } - this.announcer.setText('could not jump to root'); - return false; - }, - keyCodes: [KeyCodes.R], - }, - - /** Move the cursor out of its current context, such as a loop block. */ - contextOut: { - name: Constants.SHORTCUT_NAMES.CONTEXT_OUT, - preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace), - callback: (workspace) => { - if (this.navigation.getState(workspace) === Constants.STATE.WORKSPACE) { - this.announcer.setText('context out'); - const cursor = workspace.getCursor() as LineCursor; - if (cursor.contextOut()) { - return true; - } - } - this.announcer.setText('context out (no-op)'); - return false; - }, - keyCodes: [createSerializedKey(KeyCodes.O, [KeyCodes.SHIFT])], - }, - - /** Move the cursor in a level of context, such as into a loop. */ - contextIn: { - name: Constants.SHORTCUT_NAMES.CONTEXT_IN, - preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace), - // Print out the type of the current node. - callback: (workspace) => { - if (this.navigation.getState(workspace) === Constants.STATE.WORKSPACE) { - const cursor = workspace.getCursor() as LineCursor; - if (cursor.contextIn()) { - this.announcer.setText('context in'); - return true; - } - } - this.announcer.setText('context in (no-op)'); - return false; - }, - keyCodes: [createSerializedKey(KeyCodes.I, [KeyCodes.SHIFT])], - }, - /** Clean up the workspace. */ cleanup: { name: Constants.SHORTCUT_NAMES.CLEAN_UP,