Skip to content

Commit 9b9ffc8

Browse files
authored
fix: Remove complex navigation actions. (#309)
1 parent 0bf917d commit 9b9ffc8

File tree

2 files changed

+0
-237
lines changed

2 files changed

+0
-237
lines changed

src/line_cursor.ts

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -277,134 +277,6 @@ export class LineCursor extends Marker {
277277
);
278278
}
279279

280-
/**
281-
* Moves the cursor to the next sibling that is at the same level
282-
* of nesting.
283-
*
284-
* @returns The next sibling node, or null if the current node
285-
* is not set or there is no next sibling node.
286-
*/
287-
nextSibling(): ASTNode | null {
288-
const curNode = this.getCurNode();
289-
if (!curNode) {
290-
return null;
291-
}
292-
let newNode = null;
293-
switch (curNode.getType()) {
294-
case ASTNode.types.STACK: {
295-
// TODO: Make navigateBetweenStacks public
296-
newNode = (curNode as any).navigateBetweenStacks(true);
297-
break;
298-
}
299-
case ASTNode.types.WORKSPACE: {
300-
break;
301-
}
302-
default: {
303-
const block = curNode.getSourceBlock();
304-
const nextBlock = block?.getNextBlock();
305-
if (nextBlock) {
306-
newNode = ASTNode.createBlockNode(nextBlock);
307-
}
308-
break;
309-
}
310-
}
311-
312-
if (newNode) {
313-
this.setCurNode(newNode);
314-
}
315-
return newNode;
316-
}
317-
318-
/**
319-
* Moves the cursor to the previous sibling that is at the same level
320-
* of nesting.
321-
*
322-
* @returns The previous sibling node, or null if the current node
323-
* is not set or there is no previous sibling node.
324-
*/
325-
previousSibling(): ASTNode | null {
326-
const curNode = this.getCurNode();
327-
if (!curNode) {
328-
return null;
329-
}
330-
let newNode = null;
331-
switch (curNode.getType()) {
332-
case ASTNode.types.STACK: {
333-
// TODO: Make navigateBetweenStacks public.
334-
newNode = (curNode as any).navigateBetweenStacks(false);
335-
break;
336-
}
337-
case ASTNode.types.WORKSPACE: {
338-
break;
339-
}
340-
default: {
341-
const block = curNode.getSourceBlock();
342-
// TODO: Decide what this should do if the source block is
343-
// the first block inside a statement input.
344-
// TODO: Decide what this should do if the source block
345-
// has an output instead of a previous.
346-
const prevBlock = block?.getPreviousBlock();
347-
if (prevBlock) {
348-
newNode = ASTNode.createBlockNode(prevBlock);
349-
}
350-
break;
351-
}
352-
}
353-
354-
if (newNode) {
355-
this.setCurNode(newNode);
356-
}
357-
return newNode;
358-
}
359-
360-
/**
361-
* Moves the cursor out by one level of nesting.
362-
*
363-
* @returns The new node the cursor points to, or null if
364-
* one could not be found.
365-
*/
366-
contextOut(): ASTNode | null {
367-
const curNode = this.getCurNode();
368-
if (!curNode) {
369-
return null;
370-
}
371-
372-
// Returns null at the workspace level.
373-
// TODO: Decide where the cursor goes from the workspace level.
374-
const newNode = curNode.out();
375-
if (newNode) {
376-
this.setCurNode(newNode);
377-
}
378-
return newNode;
379-
}
380-
381-
/**
382-
* Moves the cursor in by one level of nesting.
383-
*
384-
* @returns The new node the cursor points to, or null if
385-
* one could not be found.
386-
*/
387-
contextIn(): ASTNode | null {
388-
let curNode: ASTNode | null = this.getCurNode();
389-
if (!curNode) {
390-
return null;
391-
}
392-
// If we are on a previous or output connection, go to the block level
393-
// before performing next operation.
394-
if (
395-
curNode.getType() === ASTNode.types.PREVIOUS ||
396-
curNode.getType() === ASTNode.types.OUTPUT
397-
) {
398-
curNode = curNode.next();
399-
}
400-
const newNode = curNode?.in() ?? null;
401-
402-
if (newNode) {
403-
this.setCurNode(newNode);
404-
}
405-
return newNode;
406-
}
407-
408280
/**
409281
* Uses pre order traversal to navigate the Blockly AST. This will allow
410282
* a user to easily navigate the entire Blockly AST without having to go in

src/navigation_controller.ts

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -505,115 +505,6 @@ export class NavigationController {
505505
},
506506
keyCodes: [KeyCodes.A],
507507
},
508-
509-
/** Go to the next sibling of the cursor's current location. */
510-
nextSibling: {
511-
name: Constants.SHORTCUT_NAMES.GO_TO_NEXT_SIBLING,
512-
preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace),
513-
// Jump to the next node at the same level, when in the workspace.
514-
callback: (workspace, e, shortcut) => {
515-
const cursor = workspace.getCursor() as LineCursor;
516-
517-
if (this.navigation.getState(workspace) === Constants.STATE.WORKSPACE) {
518-
if (this.fieldShortcutHandler(workspace, shortcut)) {
519-
this.announcer.setText('next sibling (handled by field)');
520-
return true;
521-
}
522-
if (cursor.nextSibling()) {
523-
this.announcer.setText('next sibling (success)');
524-
return true;
525-
}
526-
}
527-
this.announcer.setText('next sibling (no-op)');
528-
return false;
529-
},
530-
keyCodes: [KeyCodes.N],
531-
},
532-
533-
/** Go to the previous sibling of the cursor's current location. */
534-
previousSibling: {
535-
name: Constants.SHORTCUT_NAMES.GO_TO_PREVIOUS_SIBLING,
536-
preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace),
537-
// Jump to the previous node at the same level, when in the workspace.
538-
callback: (workspace, e, shortcut) => {
539-
const cursor = workspace.getCursor() as LineCursor;
540-
541-
if (this.navigation.getState(workspace) === Constants.STATE.WORKSPACE) {
542-
if (this.fieldShortcutHandler(workspace, shortcut)) {
543-
this.announcer.setText('previous sibling (handled by field)');
544-
return true;
545-
}
546-
if (cursor.previousSibling()) {
547-
this.announcer.setText('previous sibling (success)');
548-
return true;
549-
}
550-
}
551-
this.announcer.setText('previous sibling (no-op)');
552-
return false;
553-
},
554-
keyCodes: [KeyCodes.M],
555-
},
556-
557-
/** Jump to the root of the current stack. */
558-
jumpToRoot: {
559-
name: Constants.SHORTCUT_NAMES.JUMP_TO_ROOT,
560-
preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace),
561-
// Jump to the root of the current stack.
562-
callback: (workspace) => {
563-
const cursor = workspace.getCursor();
564-
if (!cursor) return false;
565-
const curNode = cursor.getCurNode();
566-
const curBlock = curNode.getSourceBlock();
567-
if (curBlock) {
568-
const rootBlock = curBlock.getRootBlock();
569-
const stackNode = ASTNode.createStackNode(rootBlock) as ASTNode;
570-
cursor.setCurNode(stackNode);
571-
this.announcer.setText('jumped to root');
572-
return true;
573-
}
574-
this.announcer.setText('could not jump to root');
575-
return false;
576-
},
577-
keyCodes: [KeyCodes.R],
578-
},
579-
580-
/** Move the cursor out of its current context, such as a loop block. */
581-
contextOut: {
582-
name: Constants.SHORTCUT_NAMES.CONTEXT_OUT,
583-
preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace),
584-
callback: (workspace) => {
585-
if (this.navigation.getState(workspace) === Constants.STATE.WORKSPACE) {
586-
this.announcer.setText('context out');
587-
const cursor = workspace.getCursor() as LineCursor;
588-
if (cursor.contextOut()) {
589-
return true;
590-
}
591-
}
592-
this.announcer.setText('context out (no-op)');
593-
return false;
594-
},
595-
keyCodes: [createSerializedKey(KeyCodes.O, [KeyCodes.SHIFT])],
596-
},
597-
598-
/** Move the cursor in a level of context, such as into a loop. */
599-
contextIn: {
600-
name: Constants.SHORTCUT_NAMES.CONTEXT_IN,
601-
preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace),
602-
// Print out the type of the current node.
603-
callback: (workspace) => {
604-
if (this.navigation.getState(workspace) === Constants.STATE.WORKSPACE) {
605-
const cursor = workspace.getCursor() as LineCursor;
606-
if (cursor.contextIn()) {
607-
this.announcer.setText('context in');
608-
return true;
609-
}
610-
}
611-
this.announcer.setText('context in (no-op)');
612-
return false;
613-
},
614-
keyCodes: [createSerializedKey(KeyCodes.I, [KeyCodes.SHIFT])],
615-
},
616-
617508
/** Clean up the workspace. */
618509
cleanup: {
619510
name: Constants.SHORTCUT_NAMES.CLEAN_UP,

0 commit comments

Comments
 (0)