Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions api-editor/gui/src/features/menuBar/MenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -133,7 +142,8 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })

dispatch(toggleComplete(declaration.id));
};
const goToPreviousMatch = () => {

const goToPreviousMatch = ({ onSameLevel }: { onSameLevel: boolean }) => {
if (!declaration || currentUserAction.type !== NoUserAction.type) {
return;
}
Expand All @@ -144,6 +154,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
pythonFilter,
annotations,
usages,
onSameLevel,
);
if (navStr !== null) {
if (wrappedAround) {
Expand All @@ -164,7 +175,8 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
dispatch(setAllExpandedInTreeView(parents));
}
};
const goToNextMatch = () => {

const goToNextMatch = ({ onSameLevel }: { onSameLevel: boolean }) => {
if (!declaration || currentUserAction.type !== NoUserAction.type) {
return;
}
Expand All @@ -175,6 +187,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
pythonFilter,
annotations,
usages,
onSameLevel,
);
if (navStr !== null) {
if (wrappedAround) {
Expand Down Expand Up @@ -230,9 +243,11 @@ export const MenuBar: React.FC<MenuBarProps> = 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);
Expand Down Expand Up @@ -351,7 +366,16 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
<MenuList>
<MenuItem
paddingLeft={8}
onClick={goToPreviousMatch}
onClick={goToParent}
isDisabled={!declaration}
icon={<FaArrowUp />}
command="Ctrl+Up"
>
Go to Parent
</MenuItem>
<MenuItem
paddingLeft={8}
onClick={() => goToPreviousMatch({ onSameLevel: false })}
isDisabled={!declaration}
icon={<FaArrowLeft />}
command="Ctrl+Left"
Expand All @@ -360,7 +384,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
</MenuItem>
<MenuItem
paddingLeft={8}
onClick={goToNextMatch}
onClick={() => goToNextMatch({ onSameLevel: false })}
isDisabled={!declaration}
icon={<FaArrowRight />}
command="Ctrl+Right"
Expand All @@ -369,12 +393,21 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
</MenuItem>
<MenuItem
paddingLeft={8}
onClick={goToParent}
onClick={() => goToPreviousMatch({ onSameLevel: true })}
isDisabled={!declaration}
icon={<FaArrowUp />}
command="Ctrl+Up"
icon={<FaAngleDoubleLeft />}
command="Ctrl+Alt+Left"
>
Go to Parent
Go to Previous Match on Same Level
</MenuItem>
<MenuItem
paddingLeft={8}
onClick={() => goToNextMatch({ onSameLevel: true })}
isDisabled={!declaration}
icon={<FaAngleDoubleRight />}
command="Ctrl+Alt+Right"
>
Go to Next Match on Same Level
</MenuItem>

<MenuDivider />
Expand Down Expand Up @@ -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 };
}

Expand All @@ -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 };
}

Expand Down