fix(app): terminal hyperlink clicks
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import type { Ghostty, Terminal as Term, FitAddon } from "ghostty-web"
|
import type { Ghostty, Terminal as Term, FitAddon } from "ghostty-web"
|
||||||
import { ComponentProps, createEffect, createSignal, onCleanup, onMount, splitProps } from "solid-js"
|
import { ComponentProps, createEffect, createSignal, onCleanup, onMount, splitProps } from "solid-js"
|
||||||
|
import { usePlatform } from "@/context/platform"
|
||||||
import { useSDK } from "@/context/sdk"
|
import { useSDK } from "@/context/sdk"
|
||||||
import { monoFontFamily, useSettings } from "@/context/settings"
|
import { monoFontFamily, useSettings } from "@/context/settings"
|
||||||
import { SerializeAddon } from "@/addons/serialize"
|
import { SerializeAddon } from "@/addons/serialize"
|
||||||
@@ -52,6 +53,7 @@ const DEFAULT_TERMINAL_COLORS: Record<"light" | "dark", TerminalColors> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Terminal = (props: TerminalProps) => {
|
export const Terminal = (props: TerminalProps) => {
|
||||||
|
const platform = usePlatform()
|
||||||
const sdk = useSDK()
|
const sdk = useSDK()
|
||||||
const settings = useSettings()
|
const settings = useSettings()
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
@@ -135,6 +137,22 @@ export const Terminal = (props: TerminalProps) => {
|
|||||||
focusTerminal()
|
focusTerminal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleLinkClick = (event: MouseEvent) => {
|
||||||
|
if (!event.shiftKey && !event.ctrlKey && !event.metaKey) return
|
||||||
|
if (event.altKey) return
|
||||||
|
if (event.button !== 0) return
|
||||||
|
|
||||||
|
const t = term
|
||||||
|
if (!t) return
|
||||||
|
|
||||||
|
const link = (t as unknown as { currentHoveredLink?: { text: string } }).currentHoveredLink
|
||||||
|
if (!link?.text) return
|
||||||
|
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopImmediatePropagation()
|
||||||
|
platform.openLink(link.text)
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
const loaded = await loadGhostty()
|
const loaded = await loadGhostty()
|
||||||
@@ -240,6 +258,9 @@ export const Terminal = (props: TerminalProps) => {
|
|||||||
container.addEventListener("pointerdown", handlePointerDown)
|
container.addEventListener("pointerdown", handlePointerDown)
|
||||||
cleanups.push(() => container.removeEventListener("pointerdown", handlePointerDown))
|
cleanups.push(() => container.removeEventListener("pointerdown", handlePointerDown))
|
||||||
|
|
||||||
|
container.addEventListener("click", handleLinkClick, { capture: true })
|
||||||
|
cleanups.push(() => container.removeEventListener("click", handleLinkClick, { capture: true }))
|
||||||
|
|
||||||
handleTextareaFocus = () => {
|
handleTextareaFocus = () => {
|
||||||
t.options.cursorBlink = true
|
t.options.cursorBlink = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user