nose-pluto/src/js/hyperlink.ts
2025-09-29 21:18:39 -07:00

24 lines
493 B
TypeScript

import { runCommand } from "./shell.js"
import { focusInput } from "./focus.js"
export function initHyperlink() {
window.addEventListener("click", handleClick)
}
function handleClick(e: MouseEvent) {
const target = e.target
if (!(target instanceof HTMLElement)) return
const a = target.closest("a")
if (!a) return
const href = a.getAttribute("href")
if (!href) return
if (href.startsWith("#")) {
e.preventDefault()
runCommand(href.slice(1))
focusInput()
}
}