multi-line cursor support
This commit is contained in:
parent
3ed6a8ea13
commit
da7c3ceae1
|
|
@ -24,6 +24,14 @@ function showCursor(e: any) {
|
|||
}
|
||||
|
||||
requestAnimationFrame(() =>
|
||||
cmdCursor.value = " ".repeat(cmdInput.selectionEnd) + cursor
|
||||
cmdCursor.value = buildBlankCursorLine() + cursor
|
||||
)
|
||||
}
|
||||
|
||||
function buildBlankCursorLine(): string {
|
||||
let line = ""
|
||||
for (const char of cmdInput.value.slice(0, cmdInput.selectionEnd)) {
|
||||
line += char === "\n" ? char : " "
|
||||
}
|
||||
return line
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
////
|
||||
// Command input history storage and navigation.
|
||||
|
||||
import { cmdInput } from "./dom.js"
|
||||
import { cmdInput, cmdLine } from "./dom.js"
|
||||
|
||||
const history: string[] = ["one", "two", "three"]
|
||||
let idx = -1
|
||||
|
|
@ -25,6 +25,8 @@ export function resetHistory() {
|
|||
}
|
||||
|
||||
function navigateHistory(e: KeyboardEvent) {
|
||||
if (cmdLine.dataset.extended) return
|
||||
|
||||
if (e.key === "ArrowUp" || (e.ctrlKey && e.key === "p")) {
|
||||
e.preventDefault()
|
||||
if (idx >= history.length - 1) return
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ function inputHandler(event: KeyboardEvent) {
|
|||
if (target?.id !== cmdInput.id) return
|
||||
|
||||
if (event.key === "Escape" || (event.ctrlKey && event.key === "c")) {
|
||||
cmdInput.value = ""
|
||||
clearInput()
|
||||
resetHistory()
|
||||
} else if (event.key === "Tab") {
|
||||
event.preventDefault()
|
||||
|
|
@ -31,5 +31,5 @@ function inputHandler(event: KeyboardEvent) {
|
|||
function clearInput() {
|
||||
cmdInput.value = ""
|
||||
cmdInput.rows = 1
|
||||
cmdLine.dataset.extended = "false"
|
||||
delete cmdLine.dataset.extended
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user