23 lines
450 B
TypeScript
23 lines
450 B
TypeScript
////
|
|
// tab completion
|
|
|
|
import { cmdInput } from "./dom"
|
|
import { commands } from "./commands"
|
|
|
|
export function initCompletion() {
|
|
cmdInput.addEventListener("keydown", handleCompletion)
|
|
}
|
|
|
|
function handleCompletion(e: KeyboardEvent) {
|
|
if (e.key !== "Tab") return
|
|
|
|
e.preventDefault()
|
|
const input = cmdInput.value
|
|
|
|
for (const command of commands) {
|
|
if (command.startsWith(input)) {
|
|
cmdInput.value = command
|
|
return
|
|
}
|
|
}
|
|
} |