UI: clear search suggestions on clearall modification (#787)

This commit is contained in:
Noah Harris 2023-09-12 02:00:20 -04:00 committed by GitHub
parent b844593e22
commit 7b2e8e5312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -102,7 +102,7 @@ export function TerminalInput(): React.ReactElement {
return Array(prefixLength).fill(" ");
}
function modifyInput(mod: string): void {
function modifyInput(mod: Modification): void {
const ref = terminalInput.current;
if (!ref) return;
const inputLength = value.length;
@ -110,7 +110,7 @@ export function TerminalInput(): React.ReactElement {
if (start === null) return;
const inputText = ref.value;
switch (mod.toLowerCase()) {
switch (mod) {
case "backspace":
if (start > 0 && start <= inputLength + 1) {
saveValue(inputText.substr(0, start - 1) + inputText.substr(start));
@ -150,18 +150,19 @@ export function TerminalInput(): React.ReactElement {
break;
case "clearall": // Deletes everything in the input
saveValue("");
resetSearch();
break;
}
}
function moveTextCursor(loc: string): void {
function moveTextCursor(loc: Location): void {
const ref = terminalInput.current;
if (!ref) return;
const inputLength = value.length;
const start = ref.selectionStart;
if (start === null) return;
switch (loc.toLowerCase()) {
switch (loc) {
case "home":
ref.setSelectionRange(0, 0);
break;
@ -461,3 +462,18 @@ export function TerminalInput(): React.ReactElement {
</>
);
}
type Modification =
| "clearall"
| "home"
| "end"
| "prevchar"
| "prevword"
| "nextword"
| "backspace"
| "deletewordbefore"
| "deletewordafter"
| "clearbefore"
| "clearafter";
type Location = "home" | "end" | "prevchar" | "nextchar" | "prevword" | "nextword";