diff --git a/src/js/main.ts b/src/js/main.ts index df2c49c..ed940e7 100644 --- a/src/js/main.ts +++ b/src/js/main.ts @@ -7,6 +7,7 @@ import { initHistory } from "./history.js" import { initHyperlink } from "./hyperlink.js" import { initInput } from "./input.js" import { initResize } from "./resize.js" +import { initScrollback } from "./scrollback.js" import { startVramCounter } from "./vram.js" import { startConnection } from "./websocket.js" @@ -19,6 +20,7 @@ initHistory() initHyperlink() initInput() initResize() +initScrollback() startConnection() startVramCounter() \ No newline at end of file diff --git a/src/js/scrollback.ts b/src/js/scrollback.ts index bf4eed6..cbb1d9f 100644 --- a/src/js/scrollback.ts +++ b/src/js/scrollback.ts @@ -2,12 +2,16 @@ // The scrollback shows your history of interacting with the shell. // input, output, etc -import { scrollback, $$ } from "./dom.js" -import { randomId } from "../shared/utils.js" import type { CommandOutput } from "../shared/types.js" +import { scrollback, cmdInput, $$ } from "./dom.js" +import { randomId } from "../shared/utils.js" type InputStatus = "waiting" | "streaming" | "ok" | "error" +export function initScrollback() { + window.addEventListener("click", handleInputClick) +} + export function autoScroll() { // requestAnimationFrame(() => scrollback.scrollTop = scrollback.scrollHeight - scrollback.clientHeight) // scrollback.scrollTop = scrollback.scrollHeight - scrollback.clientHeight @@ -63,10 +67,11 @@ export function addOutput(id: string, output: CommandOutput) { item.textContent = content const input = document.querySelector(`[data-id="${id}"].input`) - if (input instanceof HTMLLIElement) + if (input instanceof HTMLLIElement) { input.parentNode!.insertBefore(item, input.nextSibling) - else + } else { insert(item) + } autoScroll() } @@ -135,3 +140,13 @@ function processOutput(output: CommandOutput): ["html" | "text", string] { return [html ? "html" : "text", content] } + +function handleInputClick(e: MouseEvent) { + const target = e.target + + if (!(target instanceof HTMLElement)) return + + if (target.matches(".input .content")) { + cmdInput.value = target.textContent + } +}