diff --git a/api-editor/gui/src/features/menuBar/MenuBar.tsx b/api-editor/gui/src/features/menuBar/MenuBar.tsx index 1e48554c3..2880f5939 100644 --- a/api-editor/gui/src/features/menuBar/MenuBar.tsx +++ b/api-editor/gui/src/features/menuBar/MenuBar.tsx @@ -17,7 +17,16 @@ import { useToast, } from '@chakra-ui/react'; import React from 'react'; -import { FaArrowLeft, FaArrowRight, FaArrowUp, FaChevronDown, FaRedo, FaUndo } from 'react-icons/fa'; +import { + FaAngleDoubleLeft, + FaAngleDoubleRight, + FaArrowLeft, + FaArrowRight, + FaArrowUp, + FaChevronDown, + FaRedo, + FaUndo, +} from 'react-icons/fa'; import { useAppDispatch, useAppSelector, useKeyboardShortcut } from '../../app/hooks'; import { redo, @@ -133,7 +142,8 @@ export const MenuBar: React.FC = function ({ displayInferErrors }) dispatch(toggleComplete(declaration.id)); }; - const goToPreviousMatch = () => { + + const goToPreviousMatch = ({ onSameLevel }: { onSameLevel: boolean }) => { if (!declaration || currentUserAction.type !== NoUserAction.type) { return; } @@ -144,6 +154,7 @@ export const MenuBar: React.FC = function ({ displayInferErrors }) pythonFilter, annotations, usages, + onSameLevel, ); if (navStr !== null) { if (wrappedAround) { @@ -164,7 +175,8 @@ export const MenuBar: React.FC = function ({ displayInferErrors }) dispatch(setAllExpandedInTreeView(parents)); } }; - const goToNextMatch = () => { + + const goToNextMatch = ({ onSameLevel }: { onSameLevel: boolean }) => { if (!declaration || currentUserAction.type !== NoUserAction.type) { return; } @@ -175,6 +187,7 @@ export const MenuBar: React.FC = function ({ displayInferErrors }) pythonFilter, annotations, usages, + onSameLevel, ); if (navStr !== null) { if (wrappedAround) { @@ -230,9 +243,11 @@ export const MenuBar: React.FC = function ({ displayInferErrors }) useKeyboardShortcut(false, true, false, 'z', () => dispatch(undo())); useKeyboardShortcut(false, true, false, 'y', () => dispatch(redo())); useKeyboardShortcut(false, true, true, 'c', markSelectedElementAsComplete); - useKeyboardShortcut(false, true, false, 'ArrowLeft', goToPreviousMatch); - useKeyboardShortcut(false, true, false, 'ArrowRight', goToNextMatch); useKeyboardShortcut(false, true, false, 'ArrowUp', goToParent); + useKeyboardShortcut(false, true, false, 'ArrowLeft', () => goToPreviousMatch({ onSameLevel: false })); + useKeyboardShortcut(false, true, false, 'ArrowRight', () => goToNextMatch({ onSameLevel: false })); + useKeyboardShortcut(false, true, true, 'ArrowLeft', () => goToPreviousMatch({ onSameLevel: true })); + useKeyboardShortcut(false, true, true, 'ArrowRight', () => goToNextMatch({ onSameLevel: true })); useKeyboardShortcut(false, true, false, ',', expandAll); useKeyboardShortcut(false, true, false, '.', collapseAll); useKeyboardShortcut(false, true, true, ',', expandSelected); @@ -351,7 +366,16 @@ export const MenuBar: React.FC = function ({ displayInferErrors }) } + command="Ctrl+Up" + > + Go to Parent + + goToPreviousMatch({ onSameLevel: false })} isDisabled={!declaration} icon={} command="Ctrl+Left" @@ -360,7 +384,7 @@ export const MenuBar: React.FC = function ({ displayInferErrors }) goToNextMatch({ onSameLevel: false })} isDisabled={!declaration} icon={} command="Ctrl+Right" @@ -369,12 +393,21 @@ export const MenuBar: React.FC = function ({ displayInferErrors }) goToPreviousMatch({ onSameLevel: true })} isDisabled={!declaration} - icon={} - command="Ctrl+Up" + icon={} + command="Ctrl+Alt+Left" > - Go to Parent + Go to Previous Match on Same Level + + goToNextMatch({ onSameLevel: true })} + isDisabled={!declaration} + icon={} + command="Ctrl+Alt+Right" + > + Go to Next Match on Same Level @@ -513,13 +546,17 @@ const getPreviousElementPath = function ( filter: AbstractPythonFilter, annotations: AnnotationStore, usages: UsageCountStore, + onSameLevel: boolean, ): { id: string; wrappedAround: boolean } { const startIndex = getIndex(declarations, start); let currentIndex = getPreviousIndex(declarations, startIndex); let current = getElementAtIndex(declarations, currentIndex); let wrappedAround = startIndex !== null && currentIndex !== null && currentIndex >= startIndex; while (current !== null && current !== start) { - if (filter.shouldKeepDeclaration(current, annotations, usages)) { + if ( + (current.constructor === start.constructor || !onSameLevel) && + filter.shouldKeepDeclaration(current, annotations, usages) + ) { return { id: current.id, wrappedAround }; } @@ -539,13 +576,17 @@ const getNextElementPath = function ( filter: AbstractPythonFilter, annotations: AnnotationStore, usages: UsageCountStore, + onSameLevel: boolean, ): { id: string; wrappedAround: boolean } { const startIndex = getIndex(declarations, start); let currentIndex = getNextIndex(declarations, startIndex); let current = getElementAtIndex(declarations, currentIndex); let wrappedAround = startIndex !== null && currentIndex !== null && currentIndex <= startIndex; while (current !== null && current !== start) { - if (filter.shouldKeepDeclaration(current, annotations, usages)) { + if ( + (current.constructor === start.constructor || !onSameLevel) && + filter.shouldKeepDeclaration(current, annotations, usages) + ) { return { id: current.id, wrappedAround }; }