fix the cursor

This commit is contained in:
Chris Wanstrath 2025-09-21 13:43:45 -07:00
parent a4d4e36118
commit 3ed6a8ea13
2 changed files with 15 additions and 18 deletions

View File

@ -48,6 +48,14 @@
outline: 0;
border: none;
margin-left: var(--cli-margin-left);
animation: blink 1s steps(1) infinite;
}
@keyframes blink {
50% {
opacity: 0;
}
}
#command-textbox {

View File

@ -3,26 +3,14 @@
import { cmdInput, $ } from "./dom.js"
const cursorDelay = 600 // ms
const cursor = "Û"
let cmdCursor: HTMLTextAreaElement
let interval: any
export function initCursor() {
cmdCursor = $("command-cursor") as HTMLTextAreaElement
enableCursor()
setCursor()
cmdInput.addEventListener("keydown", showCursor)
cmdInput.addEventListener("keypress", showCursor)
cmdInput.addEventListener("input", showCursor)
}
function enableCursor() {
interval = setInterval(setCursor, cursorDelay)
}
function disableCursor() {
clearInterval(interval)
}
function setCursor() {
@ -30,11 +18,12 @@ function setCursor() {
}
function showCursor(e: any) {
if (e.key === "Enter") {
if (e.key === "Enter" && !e.shiftKey) {
cmdCursor.value = cursor
} else {
disableCursor()
cmdCursor.value = " ".repeat(cmdInput.value.length) + cursor
enableCursor()
return
}
requestAnimationFrame(() =>
cmdCursor.value = " ".repeat(cmdInput.selectionEnd) + cursor
)
}