From 1b547319288a82b47e1e73449c87e79383e69165 Mon Sep 17 00:00:00 2001 From: yuki hamakawa Date: Thu, 17 Sep 2026 15:30:42 +0900 Subject: [PATCH 1/2] fix(desktop): open web links from editable markdown previews --- .../createMarkdownExtensions.test.ts | 52 ++++++++++++++++++- .../createMarkdownExtensions.ts | 2 +- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.test.ts b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.test.ts index 063ad76cf60..1107021a901 100644 --- a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.test.ts +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.test.ts @@ -6,7 +6,7 @@ import { GlobalRegistrator } from "@happy-dom/global-registrator"; const alreadyRegistered = GlobalRegistrator.isRegistered; if (!alreadyRegistered) GlobalRegistrator.register(); -const { afterAll, describe, expect, it } = await import("bun:test"); +const { afterAll, describe, expect, it, spyOn } = await import("bun:test"); const { Editor } = await import("@tiptap/core"); const { createMarkdownExtensions } = await import("./createMarkdownExtensions"); @@ -42,6 +42,56 @@ function roundTrip(markdown: string): string { } } +describe("preview links", () => { + it.each([ + "a", + "strong", + ])("opens a link when clicking its %s element in an editable preview", (selector) => { + const markdown = "[**Example**](https://example.com/)"; + const editor = createEditor(markdown); + const open = spyOn(window, "open").mockReturnValue(null); + try { + const target = editor.view.dom.querySelector(selector); + expect(target).not.toBeNull(); + const event = new MouseEvent("click", { button: 0 }); + Object.defineProperty(event, "target", { value: target }); + + const handled = editor.view.someProp("handleClick", (handler) => + handler(editor.view, 1, event), + ); + + expect(handled).toBe(true); + expect(open).toHaveBeenCalledTimes(1); + expect(open).toHaveBeenCalledWith("https://example.com/", "_blank"); + expect(getMarkdown(editor)).toBe(markdown); + expect(editor.isEditable).toBe(true); + } finally { + open.mockRestore(); + editor.destroy(); + } + }); + + it("does not open a link on right-click", () => { + const editor = createEditor("[Example](https://example.com/)"); + const open = spyOn(window, "open").mockReturnValue(null); + try { + const event = new MouseEvent("click", { button: 2 }); + Object.defineProperty(event, "target", { + value: editor.view.dom.querySelector("a"), + }); + + editor.view.someProp("handleClick", (handler) => + handler(editor.view, 1, event), + ); + + expect(open).not.toHaveBeenCalled(); + } finally { + open.mockRestore(); + editor.destroy(); + } + }); +}); + describe("image attribute parsing", () => { // @tiptap/core's default attribute parser (fromString) coerces // numeric/boolean-looking strings, so ![123](x.png) used to load as diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.ts b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.ts index d5e5563e493..4940239418e 100644 --- a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.ts +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.ts @@ -242,7 +242,7 @@ export function createMarkdownExtensions({ HardBreak, History, Link.configure({ - openOnClick: !editable, + openOnClick: true, HTMLAttributes: { class: "text-primary underline underline-offset-2 hover:text-primary/80", From 521b19e1c9e536ef9e925cba97b6975d02adcc8d Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Fri, 18 Sep 2026 17:38:30 -0700 Subject: [PATCH 2/2] fix(desktop): markdown preview links follow the link click policy Links in the file preview have been dead since previews became editable (#6406). Opening them with TipTap's openOnClick sent every plain click to the system browser, bypassing Settings > Links and costing a browser tab each time you click into a link to edit it. TipTap never opens links now. TipTapMarkdownRenderer resolves the click through the shared URL click policy and only acts on http(s) hrefs. In a v2 file pane the 4-tier terminal semantics apply and the action is routed through runUrlLinkAction (split pane, new tab, system browser). Hosts without a pane store (v1 FileViewerContent, embedded views) keep the MarkdownEditor behaviour: 2-tier policy, any bound tier opens the system browser. An unbound click places the caret and flashes the same "Not bound" hint the terminal shows. The policy runs on the DOM click rather than ProseMirror's handleClick, which is never called for a shift-click. It also suppresses the native anchor navigation that a read-only preview would otherwise perform. runTerminalLinkAction and useLinkClickHint move up to usePaneRegistry so TerminalPane, openInActions and FilePane share them. Co-authored-by: Waka07 <118653322+Waka07@users.noreply.github.com> --- .../TipTapMarkdownRenderer.tsx | 60 +++++++ .../createMarkdownExtensions.test.ts | 45 ++---- .../createMarkdownExtensions.ts | 2 +- .../resolveLinkClick.test.ts | 153 ++++++++++++++++++ .../resolveLinkClick.ts | 30 ++++ .../components/FilePane/FilePane.tsx | 13 ++ .../components/FilePane/registry/types.ts | 6 + .../MarkdownPreviewView.tsx | 7 + .../components/TerminalPane/TerminalPane.tsx | 14 +- .../TerminalPane/contextMenuLinkStore.ts | 2 +- .../hooks/useLinkClickHint/index.ts | 0 .../useLinkClickHint/useLinkClickHint.ts | 0 .../utils/openInActions/openInActions.ts | 2 +- .../utils/runTerminalLinkAction/index.ts | 0 .../runTerminalLinkAction.ts | 2 +- 15 files changed, 294 insertions(+), 42 deletions(-) create mode 100644 apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/resolveLinkClick.test.ts create mode 100644 apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/resolveLinkClick.ts rename apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/{components/TerminalPane => }/hooks/useLinkClickHint/index.ts (100%) rename apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/{components/TerminalPane => }/hooks/useLinkClickHint/useLinkClickHint.ts (100%) rename apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/{components/TerminalPane => }/utils/runTerminalLinkAction/index.ts (100%) rename apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/{components/TerminalPane => }/utils/runTerminalLinkAction/runTerminalLinkAction.ts (97%) diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/TipTapMarkdownRenderer.tsx b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/TipTapMarkdownRenderer.tsx index c8455f8d29f..fcd4fad7aa9 100644 --- a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/TipTapMarkdownRenderer.tsx +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/TipTapMarkdownRenderer.tsx @@ -5,6 +5,12 @@ import { EditorState } from "@tiptap/pm/state"; import { type Editor, EditorContent, useEditor } from "@tiptap/react"; import { BubbleMenu } from "@tiptap/react/menus"; import { type MutableRefObject, useEffect, useRef } from "react"; +import { + type LinkAction, + useInlineUrlPolicy, + useTerminalUrlPolicy, +} from "renderer/lib/clickPolicy"; +import { electronTrpcClient } from "renderer/lib/trpc-client"; import { useMarkdownStyle } from "renderer/stores"; import { defaultConfig } from "../../styles/default/config"; import { tufteConfig } from "../../styles/tufte/config"; @@ -12,6 +18,7 @@ import { SelectionContextMenu } from "../SelectionContextMenu"; import { BubbleMenuToolbar } from "./components/BubbleMenuToolbar"; import { createMarkdownExtensions } from "./createMarkdownExtensions"; import { createMarkdownMerger } from "./mergeMarkdownEdits"; +import { resolveLinkClick } from "./resolveLinkClick"; const styleConfigs = { default: defaultConfig, @@ -41,6 +48,13 @@ interface TipTapMarkdownRendererProps { * change and resets the editor content and merge baseline. */ preserveSourceFormatting?: boolean; + /** + * Routes a link click to the host's panes. With it, links follow the 4-tier + * URL click policy; without it there is no pane to open into, so any bound + * tier opens the system browser, as in MarkdownEditor. + */ + onOpenUrl?: (url: string, action: LinkAction) => void; + onUnboundLinkClick?: (clientX: number, clientY: number) => void; } interface SourceTracking { @@ -119,6 +133,8 @@ export function TipTapMarkdownRenderer({ onChange, onSave, preserveSourceFormatting = false, + onOpenUrl, + onUnboundLinkClick, }: TipTapMarkdownRendererProps) { const globalStyle = useMarkdownStyle(); const style = styleProp ?? globalStyle; @@ -128,8 +144,21 @@ export function TipTapMarkdownRenderer({ const onSaveRef = useRef(onSave); const sourceTrackingRef = useRef(null); + const paneUrlPolicy = useTerminalUrlPolicy(); + const inlineUrlPolicy = useInlineUrlPolicy(); + const linkClickRef = useRef({ + getAction: inlineUrlPolicy.getAction, + onOpenUrl, + onUnboundLinkClick, + }); + onChangeRef.current = onChange; onSaveRef.current = onSave; + linkClickRef.current = { + getAction: (onOpenUrl ? paneUrlPolicy : inlineUrlPolicy).getAction, + onOpenUrl, + onUnboundLinkClick, + }; const editor = useEditor({ immediatelyRender: false, @@ -143,6 +172,37 @@ export function TipTapMarkdownRenderer({ attributes: { class: cn("focus:outline-none", editable && "min-h-[100px]"), }, + handleDOMEvents: { + // ProseMirror never calls handleClick for a shift-click (it lets the + // browser extend the selection), so the shift tiers are only + // reachable from the DOM click. + click: (_view, event) => { + const target = event.target as HTMLElement | null; + if (!target?.closest?.("a")) return false; + event.preventDefault(); + const link = linkClickRef.current; + const click = resolveLinkClick(event, link.getAction); + if (click.kind === "none") return false; + if (click.kind === "unbound") { + link.onUnboundLinkClick?.(event.clientX, event.clientY); + return false; + } + if (link.onOpenUrl) { + link.onOpenUrl(click.url, click.action); + return true; + } + electronTrpcClient.external.openUrl + .mutate(click.url) + .catch((error) => { + console.error( + "[TipTapMarkdownRenderer] Failed to open URL:", + click.url, + error, + ); + }); + return true; + }, + }, }, onCreate: ({ editor: createdEditor }) => { sourceTrackingRef.current = createSourceTracking(createdEditor, value); diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.test.ts b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.test.ts index 1107021a901..db9df5ef4a6 100644 --- a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.test.ts +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.test.ts @@ -44,46 +44,29 @@ function roundTrip(markdown: string): string { describe("preview links", () => { it.each([ - "a", - "strong", - ])("opens a link when clicking its %s element in an editable preview", (selector) => { - const markdown = "[**Example**](https://example.com/)"; - const editor = createEditor(markdown); + true, + false, + ])("never opens a link itself when editable is %p", (editable) => { + const editor = new Editor({ + editable, + extensions: createMarkdownExtensions({ + editable, + onSaveRef: { current: undefined }, + }), + content: "[**Example**](https://example.com/)", + }); const open = spyOn(window, "open").mockReturnValue(null); try { - const target = editor.view.dom.querySelector(selector); - expect(target).not.toBeNull(); const event = new MouseEvent("click", { button: 0 }); - Object.defineProperty(event, "target", { value: target }); - - const handled = editor.view.someProp("handleClick", (handler) => - handler(editor.view, 1, event), - ); - - expect(handled).toBe(true); - expect(open).toHaveBeenCalledTimes(1); - expect(open).toHaveBeenCalledWith("https://example.com/", "_blank"); - expect(getMarkdown(editor)).toBe(markdown); - expect(editor.isEditable).toBe(true); - } finally { - open.mockRestore(); - editor.destroy(); - } - }); - - it("does not open a link on right-click", () => { - const editor = createEditor("[Example](https://example.com/)"); - const open = spyOn(window, "open").mockReturnValue(null); - try { - const event = new MouseEvent("click", { button: 2 }); Object.defineProperty(event, "target", { - value: editor.view.dom.querySelector("a"), + value: editor.view.dom.querySelector("strong"), }); - editor.view.someProp("handleClick", (handler) => + const handled = editor.view.someProp("handleClick", (handler) => handler(editor.view, 1, event), ); + expect(handled).toBeFalsy(); expect(open).not.toHaveBeenCalled(); } finally { open.mockRestore(); diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.ts b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.ts index 4940239418e..4107c5f0510 100644 --- a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.ts +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/createMarkdownExtensions.ts @@ -242,7 +242,7 @@ export function createMarkdownExtensions({ HardBreak, History, Link.configure({ - openOnClick: true, + openOnClick: false, HTMLAttributes: { class: "text-primary underline underline-offset-2 hover:text-primary/80", diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/resolveLinkClick.test.ts b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/resolveLinkClick.test.ts new file mode 100644 index 00000000000..3a9e15b2603 --- /dev/null +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/resolveLinkClick.test.ts @@ -0,0 +1,153 @@ +import { GlobalRegistrator } from "@happy-dom/global-registrator"; + +const alreadyRegistered = GlobalRegistrator.isRegistered; +if (!alreadyRegistered) GlobalRegistrator.register(); + +const { afterAll, describe, expect, it } = await import("bun:test"); +const { Editor } = await import("@tiptap/core"); +const { tierFor } = await import("renderer/lib/clickPolicy/tiers"); +const { createMarkdownExtensions } = await import("./createMarkdownExtensions"); +const { resolveLinkClick } = await import("./resolveLinkClick"); + +type LinkTierMap = import("renderer/lib/clickPolicy").LinkTierMap; +type ModifierEvent = import("renderer/lib/clickPolicy").ModifierEvent; + +afterAll(async () => { + if (!alreadyRegistered) await GlobalRegistrator.unregister(); +}); + +const DEFAULT_URL_LINKS: LinkTierMap = { + plain: null, + shift: "newTab", + meta: "pane", + metaShift: "external", +}; + +const FIXTURE = [ + "[**web**](https://example.com/a)", + "[mail](mailto:a@b.c)", + "[file](file:///etc/passwd)", + "[js](javascript:alert(1))", + "[vscode](vscode://file/x)", + "[relative](./other.md)", + "[anchor](#heading)", + "plain text", +].join("\n\n"); + +function fourTier(map: LinkTierMap) { + return (event: ModifierEvent) => map[tierFor(event, "4-tier")]; +} + +function click( + selector: string, + modifiers: Partial & { button?: number }, + map: LinkTierMap = DEFAULT_URL_LINKS, +) { + const editor = new Editor({ + editable: true, + extensions: createMarkdownExtensions({ + editable: true, + onSaveRef: { current: undefined }, + }), + content: FIXTURE, + }); + try { + const target = editor.view.dom.querySelector(selector); + expect(target).not.toBeNull(); + return resolveLinkClick( + { + button: 0, + metaKey: false, + ctrlKey: false, + shiftKey: false, + ...modifiers, + target, + }, + fourTier(map), + ); + } finally { + editor.destroy(); + } +} + +describe("resolveLinkClick", () => { + it("leaves a plain click unbound so the caret can land in the link", () => { + expect(click("a[href^='https'] strong", {})).toEqual({ kind: "unbound" }); + }); + + it.each([ + [{ shiftKey: true }, "newTab"], + [{ metaKey: true }, "pane"], + [{ ctrlKey: true }, "pane"], + [{ metaKey: true, shiftKey: true }, "external"], + ] as const)("maps %p to %s", (modifiers, action) => { + expect(click("a[href^='https'] strong", modifiers)).toEqual({ + kind: "open", + url: "https://example.com/a", + action, + }); + }); + + it("follows a custom tier map", () => { + const map: LinkTierMap = { + plain: "external", + shift: null, + meta: "newTab", + metaShift: "pane", + }; + expect(click("a[href^='https']", {}, map)).toMatchObject({ + action: "external", + }); + expect(click("a[href^='https']", { shiftKey: true }, map)).toEqual({ + kind: "unbound", + }); + expect(click("a[href^='https']", { metaKey: true }, map)).toMatchObject({ + action: "newTab", + }); + }); + + it.each([ + "a[href^='mailto']", + "a[href^='./']", + "a[href^='#']", + ])("ignores the non-web link %s on every tier", (selector) => { + for (const modifiers of [ + {}, + { shiftKey: true }, + { metaKey: true }, + { metaKey: true, shiftKey: true }, + ]) { + expect(click(selector, modifiers)).toEqual({ kind: "none" }); + } + }); + + it("never renders file, javascript or custom-scheme links as anchors", () => { + const editor = new Editor({ + extensions: createMarkdownExtensions({ + editable: true, + onSaveRef: { current: undefined }, + }), + content: FIXTURE, + }); + try { + const hrefs = [...editor.view.dom.querySelectorAll("a")].map((a) => + a.getAttribute("href"), + ); + expect(hrefs).toEqual([ + "https://example.com/a", + "mailto:a@b.c", + "./other.md", + "#heading", + ]); + } finally { + editor.destroy(); + } + }); + + it("ignores right-clicks and clicks outside a link", () => { + expect(click("a[href^='https']", { button: 2, metaKey: true })).toEqual({ + kind: "none", + }); + expect(click("p:last-child", { metaKey: true })).toEqual({ kind: "none" }); + }); +}); diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/resolveLinkClick.ts b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/resolveLinkClick.ts new file mode 100644 index 00000000000..f53e8d73b35 --- /dev/null +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/resolveLinkClick.ts @@ -0,0 +1,30 @@ +import type { + ClickPolicy, + LinkAction, + ModifierEvent, +} from "renderer/lib/clickPolicy"; + +export interface LinkClickEvent extends ModifierEvent { + button: number; + target: EventTarget | null; +} + +export type ResolvedLinkClick = + | { kind: "none" } + | { kind: "unbound" } + | { kind: "open"; url: string; action: LinkAction }; + +const WEB_URL = /^https?:\/\//i; + +export function resolveLinkClick( + event: LinkClickEvent, + getAction: ClickPolicy["getAction"], +): ResolvedLinkClick { + if (event.button !== 0) return { kind: "none" }; + const target = event.target as HTMLElement | null; + const href = target?.closest?.("a")?.getAttribute("href"); + if (!href || !WEB_URL.test(href)) return { kind: "none" }; + const action = getAction(event); + if (action === null) return { kind: "unbound" }; + return { kind: "open", url: href, action }; +} diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/FilePane.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/FilePane.tsx index 7e031fd3143..e026bbffe6c 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/FilePane.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/FilePane.tsx @@ -1,9 +1,12 @@ import { useLingui } from "@lingui/react/macro"; import type { RendererContext } from "@superset/panes"; +import { FEATURE_FLAGS } from "@superset/shared/constants"; import { alert } from "@superset/ui/atoms/Alert"; import { useWorkspaceClient, workspaceTrpc } from "@superset/workspace-client"; +import { useFeatureFlagEnabled } from "posthog-js/react"; import { useCallback, useEffect } from "react"; import { MarkdownResourceProvider } from "renderer/components/MarkdownRenderer/providers/MarkdownResourceProvider"; +import type { LinkAction } from "renderer/lib/clickPolicy"; import { getBaseName } from "renderer/lib/pathBasename"; import { getPathDirectory } from "shared/absolute-paths"; import { @@ -11,6 +14,7 @@ import { useSharedFileDocument, } from "../../../../state/fileDocumentStore"; import type { FilePaneData, PaneViewerData } from "../../../../types"; +import { runUrlLinkAction } from "../../utils/runTerminalLinkAction"; import { ErrorState } from "./components/ErrorState"; import { LoadingState } from "./components/LoadingState"; import { OrphanedBanner } from "./components/OrphanedBanner"; @@ -24,6 +28,7 @@ interface FilePaneProps { export function FilePane({ context, workspaceId }: FilePaneProps) { const { t } = useLingui(); + const isPagesEnabled = useFeatureFlagEnabled(FEATURE_FLAGS.PAGES) ?? false; const data = context.pane.data as FilePaneData; const { filePath } = data; @@ -124,6 +129,13 @@ export function FilePane({ context, workspaceId }: FilePaneProps) { [context.actions, data], ); + const handleOpenUrl = useCallback( + (url: string, action: LinkAction) => { + runUrlLinkAction({ store: context.store, isPagesEnabled }, url, action); + }, + [context.store, isPagesEnabled], + ); + // Content gating — LoadingState/ErrorState rendered before view resolution when // there's nothing for the view to consume. if (document.content.kind === "loading") { @@ -196,6 +208,7 @@ export function FilePane({ context, workspaceId }: FilePaneProps) { isActive={context.isActive} onChangeView={handleChangeView} onForceView={handleForceView} + onOpenUrl={handleOpenUrl} /> diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/registry/types.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/registry/types.ts index 26cd78f36bd..b7370a2ff1b 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/registry/types.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/registry/types.ts @@ -1,6 +1,7 @@ import type { MessageDescriptor } from "@lingui/core"; import { i18n } from "@superset/i18n"; import type { ComponentType } from "react"; +import type { LinkAction } from "renderer/lib/clickPolicy"; import type { SharedFileDocument } from "../../../../../state/fileDocumentStore"; export type FileMeta = { @@ -56,6 +57,11 @@ export interface ViewProps { * gestures that would fight the host's scrolling. Defaults to false. */ embedded?: boolean; + /** + * Opens a clicked link in the host's panes. Hosts without a pane store + * omit it and links fall back to the system browser. + */ + onOpenUrl?: (url: string, action: LinkAction) => void; } export function resolveViewLabel(view: FileView, filePath: string): string { diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/registry/views/MarkdownPreviewView/MarkdownPreviewView.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/registry/views/MarkdownPreviewView/MarkdownPreviewView.tsx index 42ab1dc9740..65eeb99dab3 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/registry/views/MarkdownPreviewView/MarkdownPreviewView.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/FilePane/registry/views/MarkdownPreviewView/MarkdownPreviewView.tsx @@ -1,8 +1,10 @@ import { Trans } from "@lingui/react/macro"; import { useRef } from "react"; import { TipTapMarkdownRenderer } from "renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer"; +import { LinkHoverHint } from "renderer/lib/clickPolicy"; import { MarkdownSearch } from "renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/components/MarkdownSearch"; import { useMarkdownSearch } from "renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/hooks/useMarkdownSearch"; +import { useLinkClickHint } from "../../../../../hooks/useLinkClickHint"; import type { ViewProps } from "../../types"; import { splitFrontMatter } from "./splitFrontMatter"; @@ -15,8 +17,10 @@ export function MarkdownPreviewView({ filePath, isActive, showFrontMatterNote = true, + onOpenUrl, }: ViewProps) { const containerRef = useRef(null); + const { hint, showHint } = useLinkClickHint(); const search = useMarkdownSearch({ containerRef, isFocused: isActive, @@ -61,8 +65,11 @@ export function MarkdownPreviewView({ preserveSourceFormatting onChange={(next) => document.setContent(frontMatter + next)} onSave={() => void document.save()} + onOpenUrl={onOpenUrl} + onUnboundLinkClick={showHint} /> + ); } diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/TerminalPane.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/TerminalPane.tsx index f022616882c..e90601a7548 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/TerminalPane.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/TerminalPane.tsx @@ -46,12 +46,18 @@ import { TerminalSearch } from "renderer/screens/main/components/WorkspaceView/C import { useTheme } from "renderer/stores/theme"; import { resolveTerminalThemeType } from "renderer/stores/theme/utils"; import { isWithinWorkspacePath } from "shared/absolute-paths"; +import { useLinkClickHint } from "../../hooks/useLinkClickHint"; +import { + runFileLinkAction, + runFolderLinkAction, + runUrlLinkAction, + type TerminalLinkActionDeps, +} from "../../utils/runTerminalLinkAction"; import { TerminalAgentAutoResume } from "./components/TerminalAgentAutoResume"; import { TerminalCopiedIndicator } from "./components/TerminalCopiedIndicator"; import { TerminalRichInput } from "./components/TerminalRichInput"; import { terminalContextMenuLinkStore } from "./contextMenuLinkStore"; import { useCopyOnSelect } from "./hooks/useCopyOnSelect"; -import { useLinkClickHint } from "./hooks/useLinkClickHint"; import { type HoveredLink, useLinkHoverState } from "./hooks/useLinkHoverState"; import { useTerminalAppearance } from "./hooks/useTerminalAppearance"; import { useTerminalInterruptClear } from "./hooks/useTerminalInterruptClear"; @@ -61,12 +67,6 @@ import { } from "./richInputOpenStore"; import { PasteUploadLimitError, uploadPastedFiles } from "./uploadPastedFiles"; import { shellEscapePaths } from "./utils"; -import { - runFileLinkAction, - runFolderLinkAction, - runUrlLinkAction, - type TerminalLinkActionDeps, -} from "./utils/runTerminalLinkAction"; interface TerminalPaneProps { ctx: RendererContext; diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/contextMenuLinkStore.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/contextMenuLinkStore.ts index e6b72b6c9fa..967805d73cf 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/contextMenuLinkStore.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/contextMenuLinkStore.ts @@ -1,5 +1,5 @@ import type { LinkHoverInfo } from "renderer/lib/terminal/terminal-runtime-registry"; -import type { TerminalLinkActionDeps } from "./utils/runTerminalLinkAction"; +import type { TerminalLinkActionDeps } from "../../utils/runTerminalLinkAction"; /** * What the last right-click in a terminal pane landed on, and the deps needed diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/hooks/useLinkClickHint/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useLinkClickHint/index.ts similarity index 100% rename from apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/hooks/useLinkClickHint/index.ts rename to apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useLinkClickHint/index.ts diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/hooks/useLinkClickHint/useLinkClickHint.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useLinkClickHint/useLinkClickHint.ts similarity index 100% rename from apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/hooks/useLinkClickHint/useLinkClickHint.ts rename to apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useLinkClickHint/useLinkClickHint.ts diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/openInActions/openInActions.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/openInActions/openInActions.ts index 77efbc95fbc..59673d79f28 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/openInActions/openInActions.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/openInActions/openInActions.ts @@ -8,7 +8,7 @@ import { runFileLinkAction, runFolderLinkAction, runUrlLinkAction, -} from "../../components/TerminalPane/utils/runTerminalLinkAction"; +} from "../runTerminalLinkAction"; // Destinations, not sentences: these read under an "Open in" submenu trigger. // They name the same three targets as Settings → Links, so the menu and the diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/utils/runTerminalLinkAction/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/runTerminalLinkAction/index.ts similarity index 100% rename from apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/utils/runTerminalLinkAction/index.ts rename to apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/runTerminalLinkAction/index.ts diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/utils/runTerminalLinkAction/runTerminalLinkAction.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/runTerminalLinkAction/runTerminalLinkAction.ts similarity index 97% rename from apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/utils/runTerminalLinkAction/runTerminalLinkAction.ts rename to apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/runTerminalLinkAction/runTerminalLinkAction.ts index 1bc1ca12975..65952330265 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/utils/runTerminalLinkAction/runTerminalLinkAction.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/runTerminalLinkAction/runTerminalLinkAction.ts @@ -28,7 +28,7 @@ export interface TerminalLinkActionDeps { } export function runUrlLinkAction( - deps: TerminalLinkActionDeps, + deps: Pick, url: string, action: LinkAction, ): void {