import { useStatusBar, textInput, takeCursor, insertText } from "../scrapbox-userscript-std/dom.ts"; import { commandWatcher } from "https://raw.githubusercontent.com/takker99/ScrapVim/fix-event/commandWatcher.ts"; import { execNormal } from "./normal.ts"; import { execInsert } from "./insert.ts"; import type { Mode, State } from "./types.ts"; let state: State = { keys: [], mode: "normal", }; let timer: number | undefined; const log = useStatusBar(); const { render, dispose } = useStatusBar(); render({ type: "text", text: state.mode }); for await (const key of commandWatcher(textInput()!)) { clearTimeout(timer); state.keys.push(key); switch (state.mode) { case "normal": state = await execNormal(state); break; case "insert": state = await execInsert(state); break; } log.render({ type: "text", text: state.keys.join("") }); render({ type: "text", text: state.mode }); if (state.keys.length === 0) continue; timer = setTimeout(() => { if (state.mode === "insert") { insertText(state.keys.join("")); } state.keys = []; log.render({ type: "text", text: state.keys.join("") }); render({ type: "text", text: state.mode }); }, 1500); } log.dispose(); dispose();