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