@@ -17,7 +17,16 @@ import {
17
17
useToast ,
18
18
} from '@chakra-ui/react' ;
19
19
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' ;
21
30
import { useAppDispatch , useAppSelector , useKeyboardShortcut } from '../../app/hooks' ;
22
31
import {
23
32
redo ,
@@ -133,7 +142,8 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
133
142
134
143
dispatch ( toggleComplete ( declaration . id ) ) ;
135
144
} ;
136
- const goToPreviousMatch = ( ) => {
145
+
146
+ const goToPreviousMatch = ( { onSameLevel } : { onSameLevel : boolean } ) => {
137
147
if ( ! declaration || currentUserAction . type !== NoUserAction . type ) {
138
148
return ;
139
149
}
@@ -144,6 +154,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
144
154
pythonFilter ,
145
155
annotations ,
146
156
usages ,
157
+ onSameLevel ,
147
158
) ;
148
159
if ( navStr !== null ) {
149
160
if ( wrappedAround ) {
@@ -164,7 +175,8 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
164
175
dispatch ( setAllExpandedInTreeView ( parents ) ) ;
165
176
}
166
177
} ;
167
- const goToNextMatch = ( ) => {
178
+
179
+ const goToNextMatch = ( { onSameLevel } : { onSameLevel : boolean } ) => {
168
180
if ( ! declaration || currentUserAction . type !== NoUserAction . type ) {
169
181
return ;
170
182
}
@@ -175,6 +187,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
175
187
pythonFilter ,
176
188
annotations ,
177
189
usages ,
190
+ onSameLevel ,
178
191
) ;
179
192
if ( navStr !== null ) {
180
193
if ( wrappedAround ) {
@@ -230,9 +243,11 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
230
243
useKeyboardShortcut ( false , true , false , 'z' , ( ) => dispatch ( undo ( ) ) ) ;
231
244
useKeyboardShortcut ( false , true , false , 'y' , ( ) => dispatch ( redo ( ) ) ) ;
232
245
useKeyboardShortcut ( false , true , true , 'c' , markSelectedElementAsComplete ) ;
233
- useKeyboardShortcut ( false , true , false , 'ArrowLeft' , goToPreviousMatch ) ;
234
- useKeyboardShortcut ( false , true , false , 'ArrowRight' , goToNextMatch ) ;
235
246
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 } ) ) ;
236
251
useKeyboardShortcut ( false , true , false , ',' , expandAll ) ;
237
252
useKeyboardShortcut ( false , true , false , '.' , collapseAll ) ;
238
253
useKeyboardShortcut ( false , true , true , ',' , expandSelected ) ;
@@ -351,7 +366,16 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
351
366
< MenuList >
352
367
< MenuItem
353
368
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 } ) }
355
379
isDisabled = { ! declaration }
356
380
icon = { < FaArrowLeft /> }
357
381
command = "Ctrl+Left"
@@ -360,7 +384,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
360
384
</ MenuItem >
361
385
< MenuItem
362
386
paddingLeft = { 8 }
363
- onClick = { goToNextMatch }
387
+ onClick = { ( ) => goToNextMatch ( { onSameLevel : false } ) }
364
388
isDisabled = { ! declaration }
365
389
icon = { < FaArrowRight /> }
366
390
command = "Ctrl+Right"
@@ -369,12 +393,21 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
369
393
</ MenuItem >
370
394
< MenuItem
371
395
paddingLeft = { 8 }
372
- onClick = { goToParent }
396
+ onClick = { ( ) => goToPreviousMatch ( { onSameLevel : true } ) }
373
397
isDisabled = { ! declaration }
374
- icon = { < FaArrowUp /> }
375
- command = "Ctrl+Up "
398
+ icon = { < FaAngleDoubleLeft /> }
399
+ command = "Ctrl+Alt+Left "
376
400
>
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
378
411
</ MenuItem >
379
412
380
413
< MenuDivider />
@@ -513,13 +546,17 @@ const getPreviousElementPath = function (
513
546
filter : AbstractPythonFilter ,
514
547
annotations : AnnotationStore ,
515
548
usages : UsageCountStore ,
549
+ onSameLevel : boolean ,
516
550
) : { id : string ; wrappedAround : boolean } {
517
551
const startIndex = getIndex ( declarations , start ) ;
518
552
let currentIndex = getPreviousIndex ( declarations , startIndex ) ;
519
553
let current = getElementAtIndex ( declarations , currentIndex ) ;
520
554
let wrappedAround = startIndex !== null && currentIndex !== null && currentIndex >= startIndex ;
521
555
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
+ ) {
523
560
return { id : current . id , wrappedAround } ;
524
561
}
525
562
@@ -539,13 +576,17 @@ const getNextElementPath = function (
539
576
filter : AbstractPythonFilter ,
540
577
annotations : AnnotationStore ,
541
578
usages : UsageCountStore ,
579
+ onSameLevel : boolean ,
542
580
) : { id : string ; wrappedAround : boolean } {
543
581
const startIndex = getIndex ( declarations , start ) ;
544
582
let currentIndex = getNextIndex ( declarations , startIndex ) ;
545
583
let current = getElementAtIndex ( declarations , currentIndex ) ;
546
584
let wrappedAround = startIndex !== null && currentIndex !== null && currentIndex <= startIndex ;
547
585
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
+ ) {
549
590
return { id : current . id , wrappedAround } ;
550
591
}
551
592
0 commit comments