From da7c3ceae1e30e1d8399788f87ce515da1b92f44 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Sun, 21 Sep 2025 14:07:18 -0700 Subject: [PATCH] multi-line cursor support --- src/js/cursor.ts | 10 +++++++++- src/js/history.ts | 4 +++- src/js/input.ts | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/js/cursor.ts b/src/js/cursor.ts index 1d9f9e0..01471ce 100644 --- a/src/js/cursor.ts +++ b/src/js/cursor.ts @@ -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 } \ No newline at end of file diff --git a/src/js/history.ts b/src/js/history.ts index bdc7bf0..aaf75d4 100644 --- a/src/js/history.ts +++ b/src/js/history.ts @@ -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 diff --git a/src/js/input.ts b/src/js/input.ts index d216ac4..59a45df 100644 --- a/src/js/input.ts +++ b/src/js/input.ts @@ -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 } \ No newline at end of file