File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -17,13 +17,23 @@ export const searchHistory = (instance: Terminal, isDown?: boolean) => {
17
17
const { history, lastHistoryIndex } = instance
18
18
const endOfHistory = history . length - 1
19
19
let newIndex : number
20
+ // If User pressed Down and history is empty, return;
20
21
if ( isDown && lastHistoryIndex === 0 ) return
22
+
23
+ // if User pressed Up and user is currently on first executed command, return;
24
+ if ( ! isDown && lastHistoryIndex === history . length ) return
25
+
26
+ if ( endOfHistory < 0 ) return
21
27
// @TODO : still not consistent, index is duplicated once when searching down
28
+
29
+ // If Down key is pressed, check if value of newIndex is < 0?
30
+ // At this point, if lastHistoryIndex is 1, we should show empty string.
22
31
if ( isDown ) {
23
32
newIndex = lastHistoryIndex - 1
33
+ instance . input . value = newIndex - 1 >= 0 ? history [ newIndex - 1 ] : ''
24
34
} else {
25
- newIndex = lastHistoryIndex === endOfHistory ? 0 : lastHistoryIndex + 1
35
+ newIndex = lastHistoryIndex + 1
36
+ instance . input . value = history [ lastHistoryIndex ]
26
37
}
27
- instance . input . value = history [ isDown ? newIndex : lastHistoryIndex ]
28
38
instance . lastHistoryIndex = newIndex
29
39
}
You can’t perform that action at this time.
0 commit comments