diff --git a/src/index.tsx b/src/index.tsx index 88b8eac..547d98a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -110,18 +110,18 @@ const Terminal = ({ }; const handleInputKeyDown = (event: KeyboardEvent) => { - event.preventDefault(); if (!onInput) { return; } if (event.key === "Enter") { + event.preventDefault(); onInput(currentLineInput); setCursorPos(0); // history update setHistory((previousHistory) => currentLineInput.trim() === "" || - previousHistory[previousHistory.length - 1] === currentLineInput.trim() + previousHistory[previousHistory.length - 1] === currentLineInput.trim() ? previousHistory : [...previousHistory, currentLineInput], ); @@ -157,10 +157,12 @@ const Terminal = ({ currentLineInput.length - cursorIndex + 1, ); } else if (event.key === "ArrowUp") { - charsToRightOfCursor = currentLineInput.slice(0); + event.preventDefault(); + charsToRightOfCursor = currentLineInput.slice(currentLineInput.length); changeHistoryIndex(-1); } else if (event.key === "ArrowDown") { - charsToRightOfCursor = currentLineInput.slice(0); + event.preventDefault(); + charsToRightOfCursor = currentLineInput.slice(currentLineInput.length); changeHistoryIndex(1); }