Skip to content

Commit 1b56109

Browse files
committed
fix: minor fix on right and left arrow keys
1 parent d2cc8c3 commit 1b56109

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const Terminal = ({
121121
// history update
122122
setHistory((previousHistory) =>
123123
currentLineInput.trim() === "" ||
124-
previousHistory[previousHistory.length - 1] === currentLineInput.trim()
124+
previousHistory[previousHistory.length - 1] === currentLineInput.trim()
125125
? previousHistory
126126
: [...previousHistory, currentLineInput],
127127
);
@@ -141,7 +141,6 @@ const Terminal = ({
141141
event.key,
142142
)
143143
) {
144-
event.preventDefault();
145144
const inputElement = event.currentTarget;
146145
let charsToRightOfCursor = "";
147146
let cursorIndex =
@@ -158,10 +157,12 @@ const Terminal = ({
158157
currentLineInput.length - cursorIndex + 1,
159158
);
160159
} else if (event.key === "ArrowUp") {
161-
charsToRightOfCursor = currentLineInput.slice(0);
160+
event.preventDefault();
161+
charsToRightOfCursor = currentLineInput.slice(currentLineInput.length);
162162
changeHistoryIndex(-1);
163163
} else if (event.key === "ArrowDown") {
164-
charsToRightOfCursor = currentLineInput.slice(0);
164+
event.preventDefault();
165+
charsToRightOfCursor = currentLineInput.slice(currentLineInput.length);
165166
changeHistoryIndex(1);
166167
}
167168

0 commit comments

Comments
 (0)