nose-pluto/src/js/completion.ts
2025-10-01 22:16:38 -07:00

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
}
}
}