Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit b3e397d

Browse files
MasaraAclrianlars-reimann
authored
feat(gui): Adding buttons to go to the next/previous element of same type (#951)
* feat: Addding buttons to go to the next/previous element of same type and shortcuts for both actions Co-Authored-By: Aclrian <[email protected]> * add two = Co-Authored-By: Aclrian <[email protected]> * style: apply automatic fixes of linters * Update api-editor/gui/src/features/menuBar/MenuCaseBar.tsx Co-authored-by: Lars Reimann <[email protected]> * Update api-editor/gui/src/features/menuBar/MenuBar.tsx Co-authored-by: Lars Reimann <[email protected]> * Update api-editor/gui/src/features/menuBar/MenuBar.tsx Co-authored-by: Lars Reimann <[email protected]> * Update api-editor/gui/src/features/menuBar/MenuBar.tsx Co-authored-by: Lars Reimann <[email protected]> * KV-diagram failure Co-authored-by: Lars Reimann <[email protected]> * KV-diagram failure part 2 Co-authored-by: Lars Reimann <[email protected]> * style: apply automatic fixes of linters * feat(gui): change order and wording of menu items Co-authored-by: Aclrian <[email protected]> Co-authored-by: Lars Reimann <[email protected]> Co-authored-by: Masara <[email protected]> Co-authored-by: Aclrian <[email protected]>
1 parent 0540d30 commit b3e397d

File tree

1 file changed

+54
-13
lines changed

1 file changed

+54
-13
lines changed

api-editor/gui/src/features/menuBar/MenuBar.tsx

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ import {
1717
useToast,
1818
} from '@chakra-ui/react';
1919
import React from 'react';
20-
import { FaArrowLeft, FaArrowRight, FaArrowUp, FaChevronDown, FaRedo, FaUndo } from 'react-icons/fa';
20+
import {
21+
FaAngleDoubleLeft,
22+
FaAngleDoubleRight,
23+
FaArrowLeft,
24+
FaArrowRight,
25+
FaArrowUp,
26+
FaChevronDown,
27+
FaRedo,
28+
FaUndo,
29+
} from 'react-icons/fa';
2130
import { useAppDispatch, useAppSelector, useKeyboardShortcut } from '../../app/hooks';
2231
import {
2332
redo,
@@ -133,7 +142,8 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
133142

134143
dispatch(toggleComplete(declaration.id));
135144
};
136-
const goToPreviousMatch = () => {
145+
146+
const goToPreviousMatch = ({ onSameLevel }: { onSameLevel: boolean }) => {
137147
if (!declaration || currentUserAction.type !== NoUserAction.type) {
138148
return;
139149
}
@@ -144,6 +154,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
144154
pythonFilter,
145155
annotations,
146156
usages,
157+
onSameLevel,
147158
);
148159
if (navStr !== null) {
149160
if (wrappedAround) {
@@ -164,7 +175,8 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
164175
dispatch(setAllExpandedInTreeView(parents));
165176
}
166177
};
167-
const goToNextMatch = () => {
178+
179+
const goToNextMatch = ({ onSameLevel }: { onSameLevel: boolean }) => {
168180
if (!declaration || currentUserAction.type !== NoUserAction.type) {
169181
return;
170182
}
@@ -175,6 +187,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
175187
pythonFilter,
176188
annotations,
177189
usages,
190+
onSameLevel,
178191
);
179192
if (navStr !== null) {
180193
if (wrappedAround) {
@@ -230,9 +243,11 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
230243
useKeyboardShortcut(false, true, false, 'z', () => dispatch(undo()));
231244
useKeyboardShortcut(false, true, false, 'y', () => dispatch(redo()));
232245
useKeyboardShortcut(false, true, true, 'c', markSelectedElementAsComplete);
233-
useKeyboardShortcut(false, true, false, 'ArrowLeft', goToPreviousMatch);
234-
useKeyboardShortcut(false, true, false, 'ArrowRight', goToNextMatch);
235246
useKeyboardShortcut(false, true, false, 'ArrowUp', goToParent);
247+
useKeyboardShortcut(false, true, false, 'ArrowLeft', () => goToPreviousMatch({ onSameLevel: false }));
248+
useKeyboardShortcut(false, true, false, 'ArrowRight', () => goToNextMatch({ onSameLevel: false }));
249+
useKeyboardShortcut(false, true, true, 'ArrowLeft', () => goToPreviousMatch({ onSameLevel: true }));
250+
useKeyboardShortcut(false, true, true, 'ArrowRight', () => goToNextMatch({ onSameLevel: true }));
236251
useKeyboardShortcut(false, true, false, ',', expandAll);
237252
useKeyboardShortcut(false, true, false, '.', collapseAll);
238253
useKeyboardShortcut(false, true, true, ',', expandSelected);
@@ -351,7 +366,16 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
351366
<MenuList>
352367
<MenuItem
353368
paddingLeft={8}
354-
onClick={goToPreviousMatch}
369+
onClick={goToParent}
370+
isDisabled={!declaration}
371+
icon={<FaArrowUp />}
372+
command="Ctrl+Up"
373+
>
374+
Go to Parent
375+
</MenuItem>
376+
<MenuItem
377+
paddingLeft={8}
378+
onClick={() => goToPreviousMatch({ onSameLevel: false })}
355379
isDisabled={!declaration}
356380
icon={<FaArrowLeft />}
357381
command="Ctrl+Left"
@@ -360,7 +384,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
360384
</MenuItem>
361385
<MenuItem
362386
paddingLeft={8}
363-
onClick={goToNextMatch}
387+
onClick={() => goToNextMatch({ onSameLevel: false })}
364388
isDisabled={!declaration}
365389
icon={<FaArrowRight />}
366390
command="Ctrl+Right"
@@ -369,12 +393,21 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
369393
</MenuItem>
370394
<MenuItem
371395
paddingLeft={8}
372-
onClick={goToParent}
396+
onClick={() => goToPreviousMatch({ onSameLevel: true })}
373397
isDisabled={!declaration}
374-
icon={<FaArrowUp />}
375-
command="Ctrl+Up"
398+
icon={<FaAngleDoubleLeft />}
399+
command="Ctrl+Alt+Left"
376400
>
377-
Go to Parent
401+
Go to Previous Match on Same Level
402+
</MenuItem>
403+
<MenuItem
404+
paddingLeft={8}
405+
onClick={() => goToNextMatch({ onSameLevel: true })}
406+
isDisabled={!declaration}
407+
icon={<FaAngleDoubleRight />}
408+
command="Ctrl+Alt+Right"
409+
>
410+
Go to Next Match on Same Level
378411
</MenuItem>
379412

380413
<MenuDivider />
@@ -513,13 +546,17 @@ const getPreviousElementPath = function (
513546
filter: AbstractPythonFilter,
514547
annotations: AnnotationStore,
515548
usages: UsageCountStore,
549+
onSameLevel: boolean,
516550
): { id: string; wrappedAround: boolean } {
517551
const startIndex = getIndex(declarations, start);
518552
let currentIndex = getPreviousIndex(declarations, startIndex);
519553
let current = getElementAtIndex(declarations, currentIndex);
520554
let wrappedAround = startIndex !== null && currentIndex !== null && currentIndex >= startIndex;
521555
while (current !== null && current !== start) {
522-
if (filter.shouldKeepDeclaration(current, annotations, usages)) {
556+
if (
557+
(current.constructor === start.constructor || !onSameLevel) &&
558+
filter.shouldKeepDeclaration(current, annotations, usages)
559+
) {
523560
return { id: current.id, wrappedAround };
524561
}
525562

@@ -539,13 +576,17 @@ const getNextElementPath = function (
539576
filter: AbstractPythonFilter,
540577
annotations: AnnotationStore,
541578
usages: UsageCountStore,
579+
onSameLevel: boolean,
542580
): { id: string; wrappedAround: boolean } {
543581
const startIndex = getIndex(declarations, start);
544582
let currentIndex = getNextIndex(declarations, startIndex);
545583
let current = getElementAtIndex(declarations, currentIndex);
546584
let wrappedAround = startIndex !== null && currentIndex !== null && currentIndex <= startIndex;
547585
while (current !== null && current !== start) {
548-
if (filter.shouldKeepDeclaration(current, annotations, usages)) {
586+
if (
587+
(current.constructor === start.constructor || !onSameLevel) &&
588+
filter.shouldKeepDeclaration(current, annotations, usages)
589+
) {
549590
return { id: current.id, wrappedAround };
550591
}
551592

0 commit comments

Comments
 (0)