Command backlog only when changed, trim commands

This commit is contained in:
Daniel Kluge 2022-02-05 23:44:32 +01:00
parent 01571c689c
commit ddb4c11323

View File

@ -50,6 +50,7 @@ const REPLInput: NextPage<REPLInputParams> = ({historyCallback, historyClear, in
const currentInput = input.value.toLowerCase();
// Force lowercase
input.value = currentInput;
if (currentInput.trim() === "") input.value = "";
if (currentInput.includes(" ")) {
// Command already typed
@ -83,8 +84,8 @@ const REPLInput: NextPage<REPLInputParams> = ({historyCallback, historyClear, in
if (e.key === "Enter") {
e.preventDefault();
const command = (e.target as HTMLInputElement).value;
setCmdHistory(cmdHistory.concat([command]).splice(0, 100));
const command = (e.target as HTMLInputElement).value.trim();
if (cmdHistory.at(-1) !== command) setCmdHistory(cmdHistory.concat([command]).splice(0, 100));
clearInput(input);
setInCmdHistory(-1);
setCurrentCmd([]);