From 061ad0932971e80d3adb876c25bea8dd95ffe95f Mon Sep 17 00:00:00 2001 From: caezium <113233555+caezium@users.noreply.github.com> Date: Mon, 20 Jul 2026 02:07:44 +0800 Subject: [PATCH] refactor(web): clarify preview link action --- apps/web/src/components/ChatMarkdown.tsx | 2 +- .../chat/externalLinkContextMenu.test.ts | 18 +++++++++--------- .../components/chat/externalLinkContextMenu.ts | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index 10c9df175a..36fab2d5da 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -1421,7 +1421,7 @@ function ChatMarkdown({ href, position: { x: event.clientX, y: event.clientY }, showContextMenu: (items, position) => api.contextMenu.show(items, position), - openInBrowser: async (target) => { + openInPreview: async (target) => { const result = await openExternalLinkInPreview(target); if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) { reportMarkdownActionFailure( diff --git a/apps/web/src/components/chat/externalLinkContextMenu.test.ts b/apps/web/src/components/chat/externalLinkContextMenu.test.ts index 67cd4ae015..1f2b6b5ae0 100644 --- a/apps/web/src/components/chat/externalLinkContextMenu.test.ts +++ b/apps/web/src/components/chat/externalLinkContextMenu.test.ts @@ -2,16 +2,16 @@ import { describe, expect, it, vi } from "vite-plus/test"; import { isExternalWebLink, showExternalLinkContextMenu } from "./externalLinkContextMenu"; -function createHarness(selection: "open-in-browser" | "open-external" | "copy-link" | null) { +function createHarness(selection: "open-in-preview" | "open-external" | "copy-link" | null) { const showContextMenu = vi.fn().mockResolvedValue(selection); - const openInBrowser = vi.fn().mockResolvedValue(undefined); + const openInPreview = vi.fn().mockResolvedValue(undefined); const openExternal = vi.fn().mockResolvedValue(undefined); const copyLink = vi.fn().mockResolvedValue(undefined); const reportFailure = vi.fn(); return { showContextMenu, - openInBrowser, + openInPreview, openExternal, copyLink, reportFailure, @@ -30,13 +30,13 @@ describe("external chat link context menu", () => { expect(harness.showContextMenu).toHaveBeenCalledWith( [ - { id: "open-in-browser", label: "Open in integrated browser" }, + { id: "open-in-preview", label: "Open in integrated browser" }, { id: "open-external", label: "Open in system browser" }, { id: "copy-link", label: "Copy Link" }, ], { x: 12, y: 24 }, ); - expect(harness.openInBrowser).not.toHaveBeenCalled(); + expect(harness.openInPreview).not.toHaveBeenCalled(); expect(harness.openExternal).not.toHaveBeenCalled(); expect(harness.copyLink).not.toHaveBeenCalled(); }); @@ -48,12 +48,12 @@ describe("external chat link context menu", () => { await showExternalLinkContextMenu({ href, position: { x: 1, y: 2 }, ...harness }); expect(harness.copyLink).toHaveBeenCalledWith(href); - expect(harness.openInBrowser).not.toHaveBeenCalled(); + expect(harness.openInPreview).not.toHaveBeenCalled(); expect(harness.openExternal).not.toHaveBeenCalled(); }); it.each([ - ["open-in-browser" as const, "openInBrowser" as const], + ["open-in-preview" as const, "openInPreview" as const], ["open-external" as const, "openExternal" as const], ])("preserves the %s action", async (selection, expectedCallback) => { const harness = createHarness(selection); @@ -91,13 +91,13 @@ describe("external chat link context menu", () => { }); expect(harness.reportFailure).toHaveBeenCalledWith("show-link-context-menu", cause); - expect(harness.openInBrowser).not.toHaveBeenCalled(); + expect(harness.openInPreview).not.toHaveBeenCalled(); expect(harness.openExternal).not.toHaveBeenCalled(); expect(harness.copyLink).not.toHaveBeenCalled(); }); it.each([ - ["open-in-browser" as const, "openInBrowser" as const, "open-link-in-preview"], + ["open-in-preview" as const, "openInPreview" as const, "open-link-in-preview"], ["open-external" as const, "openExternal" as const, "open-link-external"], ])("reports a failed %s action", async (selection, callback, operation) => { const harness = createHarness(selection); diff --git a/apps/web/src/components/chat/externalLinkContextMenu.ts b/apps/web/src/components/chat/externalLinkContextMenu.ts index 408945cec9..020c6169ff 100644 --- a/apps/web/src/components/chat/externalLinkContextMenu.ts +++ b/apps/web/src/components/chat/externalLinkContextMenu.ts @@ -1,6 +1,6 @@ import type { ContextMenuItem } from "@t3tools/contracts"; -export type ExternalLinkContextMenuAction = "open-in-browser" | "open-external" | "copy-link"; +export type ExternalLinkContextMenuAction = "open-in-preview" | "open-external" | "copy-link"; export type ExternalLinkContextMenuFailureOperation = | "show-link-context-menu" @@ -9,13 +9,13 @@ export type ExternalLinkContextMenuFailureOperation = | "copy-link"; const FAILURE_OPERATION_BY_ACTION = { - "open-in-browser": "open-link-in-preview", + "open-in-preview": "open-link-in-preview", "open-external": "open-link-external", "copy-link": "copy-link", } as const satisfies Record; const EXTERNAL_LINK_CONTEXT_MENU_ITEMS = [ - { id: "open-in-browser", label: "Open in integrated browser" }, + { id: "open-in-preview", label: "Open in integrated browser" }, { id: "open-external", label: "Open in system browser" }, { id: "copy-link", label: "Copy Link" }, ] as const satisfies readonly ContextMenuItem[]; @@ -27,7 +27,7 @@ interface ShowExternalLinkContextMenuOptions { items: readonly ContextMenuItem[], position: { readonly x: number; readonly y: number }, ) => Promise; - readonly openInBrowser: (href: string) => Promise; + readonly openInPreview: (href: string) => Promise; readonly openExternal: (href: string) => Promise; readonly copyLink: (href: string) => Promise; readonly reportFailure: ( @@ -49,7 +49,7 @@ export async function showExternalLinkContextMenu({ href, position, showContextMenu, - openInBrowser, + openInPreview, openExternal, copyLink, reportFailure, @@ -63,8 +63,8 @@ export async function showExternalLinkContextMenu({ } try { - if (action === "open-in-browser") { - await openInBrowser(href); + if (action === "open-in-preview") { + await openInPreview(href); } else if (action === "open-external") { await openExternal(href); } else if (action === "copy-link") {