Add rudimentary tab completion from history to CLI

This commit is contained in:
Oliver Blanthorn 2017-11-09 12:44:57 +00:00
parent c2e744ec11
commit 15b6ec76cd
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3

View file

@ -42,6 +42,23 @@ clInput.addEventListener("keydown", function (keyevent) {
// should probably just defer to another library
case "c":
if (keyevent.ctrlKey) hide_and_clear()
break
case "f":
if (keyevent.ctrlKey){
// Stop ctrl+f from doing find
keyevent.preventDefault()
keyevent.stopPropagation()
tabcomplete()
}
break
case "Tab":
// Stop tab from losing focus
keyevent.preventDefault()
keyevent.stopPropagation()
tabcomplete()
break
}
})
@ -59,6 +76,13 @@ function hide_and_clear(){
sendExstr("hidecmdline")
}
function tabcomplete(){
let fragment = clInput.value
let matches = state.cmdHistory.filter((key)=>key.startsWith(fragment))
let mostrecent = matches[matches.length - 1]
if (mostrecent != undefined) clInput.value = mostrecent
}
function history(n){
completions.innerHTML = ""
if (cmdline_history_position == 0){