@@ -14,6 +14,7 @@ import {
14
14
MenuOptionGroup ,
15
15
Spacer ,
16
16
useColorMode ,
17
+ useToast ,
17
18
} from '@chakra-ui/react' ;
18
19
import React from 'react' ;
19
20
import { FaArrowLeft , FaArrowRight , FaArrowUp , FaChevronDown , FaRedo , FaUndo } from 'react-icons/fa' ;
@@ -69,6 +70,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
69
70
const { colorMode, toggleColorMode } = useColorMode ( ) ;
70
71
const dispatch = useAppDispatch ( ) ;
71
72
const navigate = useNavigate ( ) ;
73
+ const toast = useToast ( ) ;
72
74
73
75
const annotationStore = useAppSelector ( selectAnnotationStore ) ;
74
76
const sortingMode = useAppSelector ( selectSortingMode ) ;
@@ -119,8 +121,24 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
119
121
return ;
120
122
}
121
123
122
- let navStr = getPreviousElementPath ( allDeclarations , declaration , pythonFilter , annotations , usages ) ;
124
+ let { id : navStr , wrappedAround } = getPreviousElementPath (
125
+ allDeclarations ,
126
+ declaration ,
127
+ pythonFilter ,
128
+ annotations ,
129
+ usages ,
130
+ ) ;
123
131
if ( navStr !== null ) {
132
+ if ( wrappedAround ) {
133
+ toast ( {
134
+ title : 'Start of List' ,
135
+ description : 'You reached the start of the list. Going back to its end\u2026' ,
136
+ status : 'info' ,
137
+ duration : 4000 ,
138
+ isClosable : true ,
139
+ } ) ;
140
+ }
141
+
124
142
//navigate to element
125
143
navigate ( `/${ navStr } ` ) ;
126
144
@@ -134,8 +152,24 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
134
152
return ;
135
153
}
136
154
137
- let navStr = getNextElementPath ( allDeclarations , declaration , pythonFilter , annotations , usages ) ;
155
+ let { id : navStr , wrappedAround } = getNextElementPath (
156
+ allDeclarations ,
157
+ declaration ,
158
+ pythonFilter ,
159
+ annotations ,
160
+ usages ,
161
+ ) ;
138
162
if ( navStr !== null ) {
163
+ if ( wrappedAround ) {
164
+ toast ( {
165
+ title : 'End of List' ,
166
+ description : 'You reached the end of the list. Going back to its start\u2026' ,
167
+ status : 'info' ,
168
+ duration : 4000 ,
169
+ isClosable : true ,
170
+ } ) ;
171
+ }
172
+
139
173
//navigate to element
140
174
navigate ( `/${ navStr } ` ) ;
141
175
@@ -460,17 +494,23 @@ const getPreviousElementPath = function (
460
494
filter : AbstractPythonFilter ,
461
495
annotations : AnnotationStore ,
462
496
usages : UsageCountStore ,
463
- ) : string {
497
+ ) : { id : string ; wrappedAround : boolean } {
464
498
let currentIndex = getPreviousIndex ( declarations , getIndex ( declarations , start ) ) ;
465
499
let current = getElementAtIndex ( declarations , currentIndex ) ;
500
+ let wrappedAround = false ;
466
501
while ( current !== null && current !== start ) {
467
502
if ( filter . shouldKeepDeclaration ( current , annotations , usages ) ) {
468
- return current . id ;
503
+ return { id : current . id , wrappedAround } ;
469
504
}
505
+
506
+ const oldIndex = currentIndex ;
470
507
currentIndex = getPreviousIndex ( declarations , currentIndex ) ;
471
508
current = getElementAtIndex ( declarations , currentIndex ) ;
509
+ if ( oldIndex !== null && currentIndex !== null && currentIndex >= oldIndex ) {
510
+ wrappedAround = true ;
511
+ }
472
512
}
473
- return start . id ;
513
+ return { id : start . id , wrappedAround } ;
474
514
} ;
475
515
476
516
const getNextElementPath = function (
@@ -479,17 +519,23 @@ const getNextElementPath = function (
479
519
filter : AbstractPythonFilter ,
480
520
annotations : AnnotationStore ,
481
521
usages : UsageCountStore ,
482
- ) : string {
522
+ ) : { id : string ; wrappedAround : boolean } {
483
523
let currentIndex = getNextIndex ( declarations , getIndex ( declarations , start ) ) ;
484
524
let current = getElementAtIndex ( declarations , currentIndex ) ;
525
+ let wrappedAround = false ;
485
526
while ( current !== null && current !== start ) {
486
527
if ( filter . shouldKeepDeclaration ( current , annotations , usages ) ) {
487
- return current . id ;
528
+ return { id : current . id , wrappedAround } ;
488
529
}
530
+
531
+ const oldIndex = currentIndex ;
489
532
currentIndex = getNextIndex ( declarations , currentIndex ) ;
490
533
current = getElementAtIndex ( declarations , currentIndex ) ;
534
+ if ( oldIndex !== null && currentIndex !== null && currentIndex <= oldIndex ) {
535
+ wrappedAround = true ;
536
+ }
491
537
}
492
- return start . id ;
538
+ return { id : start . id , wrappedAround } ;
493
539
} ;
494
540
495
541
const getPreviousIndex = function ( declarations : PythonDeclaration [ ] , currentIndex : number | null ) : number | null {
0 commit comments