Skip to content

Commit 879d889

Browse files
authored
fix: #14: fixed History keyboard traveling (#17)
1 parent a732215 commit 879d889

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/helpers/history.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,23 @@ export const searchHistory = (instance: Terminal, isDown?: boolean) => {
1717
const { history, lastHistoryIndex } = instance
1818
const endOfHistory = history.length - 1
1919
let newIndex: number
20+
// If User pressed Down and history is empty, return;
2021
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
2127
// @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.
2231
if (isDown) {
2332
newIndex = lastHistoryIndex - 1
33+
instance.input.value = newIndex - 1 >= 0 ? history[newIndex - 1] : ''
2434
} else {
25-
newIndex = lastHistoryIndex === endOfHistory ? 0 : lastHistoryIndex + 1
35+
newIndex = lastHistoryIndex + 1
36+
instance.input.value = history[lastHistoryIndex]
2637
}
27-
instance.input.value = history[isDown ? newIndex : lastHistoryIndex]
2838
instance.lastHistoryIndex = newIndex
2939
}

0 commit comments

Comments
 (0)