Skip to content

Commit 541d0e9

Browse files
authored
Merge pull request #65 from leonardo3130/fix/fix-typing-bug
fix typing event bug
2 parents 4f4ad65 + 1b56109 commit 541d0e9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ const Terminal = ({
110110
};
111111

112112
const handleInputKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
113-
event.preventDefault();
114113
if (!onInput) {
115114
return;
116115
}
117116
if (event.key === "Enter") {
117+
event.preventDefault();
118118
onInput(currentLineInput);
119119
setCursorPos(0);
120120

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
);
@@ -157,10 +157,12 @@ const Terminal = ({
157157
currentLineInput.length - cursorIndex + 1,
158158
);
159159
} else if (event.key === "ArrowUp") {
160-
charsToRightOfCursor = currentLineInput.slice(0);
160+
event.preventDefault();
161+
charsToRightOfCursor = currentLineInput.slice(currentLineInput.length);
161162
changeHistoryIndex(-1);
162163
} else if (event.key === "ArrowDown") {
163-
charsToRightOfCursor = currentLineInput.slice(0);
164+
event.preventDefault();
165+
charsToRightOfCursor = currentLineInput.slice(currentLineInput.length);
164166
changeHistoryIndex(1);
165167
}
166168

0 commit comments

Comments
 (0)