feat: better control of arrow keys
This commit is contained in:
parent
c658d5492c
commit
f2220ba1b0
1 changed files with 14 additions and 0 deletions
|
@ -32,6 +32,11 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
|||
inputEl.setSelectionRange(pos, pos)
|
||||
}
|
||||
|
||||
function cursorTouchesPrompt() {
|
||||
const promptEnd = inputEl.value.lastIndexOf(prompt) + prompt.length
|
||||
return inputEl.selectionStart === promptEnd
|
||||
}
|
||||
|
||||
function setFocus() {
|
||||
inputEl.focus()
|
||||
}
|
||||
|
@ -189,6 +194,15 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
|||
case 'Backspace':
|
||||
if (cursorAtPrompt()) ev.preventDefault()
|
||||
break
|
||||
case 'ArrowUp':
|
||||
// TODO: commandHistory(-1)
|
||||
ev.preventDefault()
|
||||
break
|
||||
case 'ArrowLeft':
|
||||
if (cursorTouchesPrompt()) ev.preventDefault()
|
||||
break
|
||||
default:
|
||||
console.debug('key pressed:', ev.key, ev.keyCode)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue