A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io
Rust ai-toolsclaude-codecodexdeepseek-harnessdesktop-appgrokgrokbuildhermeskimi-codemcpopen-sourceopencodepiprovider-managementrustskillsskills-managementtauriwsl-support
feat(ui): 禁用界面文本默认选中与系统右键菜单,保留可复制区域 (#8761)
zydo55f5db084d53
diff --git a/src/components/DatabaseUpgrade.tsx b/src/components/DatabaseUpgrade.tsxindex 2eca7b2f1..087d805ad 100644--- a/src/components/DatabaseUpgrade.tsx+++ b/src/components/DatabaseUpgrade.tsx@@ -165,7 +165,7 @@ export function DatabaseUpgrade({ payload }: DatabaseUpgradeProps) {</div>{/* 错误详情 / 数据库路径 */}- <div className="space-y-1 rounded-lg border border-border/50 bg-subtle p-3 text-xs text-fg-2">+ <div className="selectable space-y-1 rounded-lg border border-border/50 bg-subtle p-3 text-xs text-fg-2">{payload.error && (<p className="break-words font-mono">{payload.error}</p>)}diff --git a/src/components/sessions/reader/SessionDiff.tsx b/src/components/sessions/reader/SessionDiff.tsxindex 8b6bbe561..afa868bc0 100644--- a/src/components/sessions/reader/SessionDiff.tsx+++ b/src/components/sessions/reader/SessionDiff.tsx@@ -239,7 +239,7 @@ export const SessionDiff = memo(function SessionDiff({<divtabIndex={0}className={cn(- "max-h-[480px] overflow-auto rounded-[8px] border border-border bg-surface font-mono text-caption outline-none focus-visible:ring-2 focus-visible:ring-ring",+ "selectable max-h-[480px] overflow-auto rounded-[8px] border border-border bg-surface font-mono text-caption outline-none focus-visible:ring-2 focus-visible:ring-ring",className,)}>diff --git a/src/components/sessions/reader/SessionMarkdown.tsx b/src/components/sessions/reader/SessionMarkdown.tsxindex 9aa08abf4..82329b8ce 100644--- a/src/components/sessions/reader/SessionMarkdown.tsx+++ b/src/components/sessions/reader/SessionMarkdown.tsx@@ -521,7 +521,7 @@ export const SessionPlainText = memo(function SessionPlainText({return (<divclassName={cn(- "min-w-0 break-words text-body text-fg-1 [overflow-wrap:anywhere]",+ "selectable min-w-0 break-words text-body text-fg-1 [overflow-wrap:anywhere]",className,)}>@@ -1126,7 +1126,7 @@ export const SessionMarkdown = memo(function SessionMarkdown({<divdata-session-markdown=""className={cn(- "min-w-0 break-words [overflow-wrap:anywhere]",+ "selectable min-w-0 break-words [overflow-wrap:anywhere]",VARIANT_CLASS[variant],className,)}diff --git a/src/components/settings/WebdavSyncSection.tsx b/src/components/settings/WebdavSyncSection.tsxindex ebc07a738..8de5f2c69 100644--- a/src/components/settings/WebdavSyncSection.tsx+++ b/src/components/settings/WebdavSyncSection.tsx@@ -1367,7 +1367,7 @@ export function WebdavSyncSection({</p>)}{showAutoSyncError && (- <div className="rounded-lg border border-transparent bg-danger-soft px-3 py-2 text-xs text-danger-text">+ <div className="selectable rounded-lg border border-transparent bg-danger-soft px-3 py-2 text-xs text-danger-text"><p className="font-medium">{t("settings.webdavSync.autoSyncLastErrorTitle")}</p>@@ -1707,7 +1707,7 @@ export function WebdavSyncSection({</p>)}{s3ShowAutoSyncError && (- <div className="rounded-lg border border-transparent bg-danger-soft px-3 py-2 text-xs text-danger-text">+ <div className="selectable rounded-lg border border-transparent bg-danger-soft px-3 py-2 text-xs text-danger-text"><p className="font-medium">{t("settings.s3Sync.autoSyncLastErrorTitle")}</p>diff --git a/src/components/ui/sonner.tsx b/src/components/ui/sonner.tsxindex 228bdb94e..518403d5b 100644--- a/src/components/ui/sonner.tsx+++ b/src/components/ui/sonner.tsx@@ -21,7 +21,7 @@ export function Toaster() {classNames: {toast:"group flex w-full items-center gap-2.5 rounded-panel border border-border bg-surface py-2.5 pe-3.5 ps-3 text-body text-fg-1 shadow-v7-lg",- content: "flex min-w-0 flex-1 flex-col gap-0.5",+ content: "flex min-w-0 flex-1 flex-col gap-0.5 selectable",title: "text-body font-medium",description: "text-caption text-fg-2",// 状态靠图标颜色区分:成功绿、失败红、警告琥珀、提示灰diff --git a/src/components/usage/RequestDetailPanel.tsx b/src/components/usage/RequestDetailPanel.tsxindex 40dc07d5e..a08144b21 100644--- a/src/components/usage/RequestDetailPanel.tsx+++ b/src/components/usage/RequestDetailPanel.tsx@@ -95,6 +95,7 @@ function DetailSection({ title, rows }: { title: string; rows: DetailRow[] }) {className={cn("m-0 min-w-0 flex-1 truncate text-end tabular-nums",row.mono ? "font-mono text-caption" : "text-body",+ row.key === "requestId" && "selectable",row.strong && "font-semibold",row.muted ? "text-fg-3" : "text-fg-1",)}@@ -382,7 +383,7 @@ function RequestDetailBody({ request }: { request: RequestLog }) {<h3 className="m-0 text-strong font-semibold text-danger-text">{t("usage.errorMessage")}</h3>- <p className="m-0 whitespace-pre-wrap break-words rounded-panel bg-danger-soft px-3.5 py-2.5 font-mono text-caption text-fg-1">+ <p className="selectable m-0 whitespace-pre-wrap break-words rounded-panel bg-danger-soft px-3.5 py-2.5 font-mono text-caption text-fg-1">{request.errorMessage}</p></section>diff --git a/src/index.css b/src/index.cssindex 787d0c6ac..144a592fe 100644--- a/src/index.css+++ b/src/index.css@@ -738,3 +738,31 @@ html[data-density="comfortable"] .auth-quota-refresh {min-width: 0;}}++/*+ * Desktop app convention: UI text is not selectable by default. Dragging on+ * cards, labels or buttons should not paint a selection, and the WebView's+ * system context menu (macOS: Look Up / Share / Services) should not appear+ * on app chrome. Editable fields and content meant to be copied opt back in+ * via the selector list below — keep it in sync with the guard in+ * src/lib/disableContextMenu.ts.+ */+body {+ user-select: none;+ -webkit-user-select: none;+ cursor: default;+}++input,+textarea,+select,+[contenteditable="true"],+[contenteditable=""],+.cm-editor,+pre,+code,+.selectable {+ user-select: text;+ -webkit-user-select: text;+ cursor: auto;+}diff --git a/src/lib/disableContextMenu.ts b/src/lib/disableContextMenu.tsindex d2a355975..234e90602 100644--- a/src/lib/disableContextMenu.ts+++ b/src/lib/disableContextMenu.ts@@ -1,6 +1,9 @@-/** 可编辑区域保留原生右键菜单(复制、粘贴、拼写检查等)。 */+/**+ * 可编辑区域与可复制内容保留原生右键菜单(复制、粘贴、拼写检查等)。+ * 与 src/index.css 中的 user-select 白名单保持同步。+ */const EDITABLE_SELECTOR =- "input, textarea, select, [contenteditable='true'], .cm-editor";+ "input, textarea, select, [contenteditable='true'], [contenteditable=''], .cm-editor, pre, code, .selectable";/*** 禁用 WebView 默认的浏览器右键菜单(后退、刷新、另存为、打印等)。diff --git a/tests/lib/disableContextMenu.test.ts b/tests/lib/disableContextMenu.test.tsnew file mode 100644index 000000000..452f2d064--- /dev/null+++ b/tests/lib/disableContextMenu.test.ts@@ -0,0 +1,56 @@+import { describe, it, expect } from "vitest";+import { disableContextMenu } from "@/lib/disableContextMenu";++function dispatchContextMenu(el: Element): boolean {+ const event = new MouseEvent("contextmenu", {+ bubbles: true,+ cancelable: true,+ });+ el.dispatchEvent(event);+ return event.defaultPrevented;+}++describe("disableContextMenu", () => {+ disableContextMenu();++ it("suppresses the menu on plain app chrome", () => {+ document.body.innerHTML = `<div class="card"><span>label</span></div>`;+ const target = document.querySelector("span")!;+ expect(dispatchContextMenu(target)).toBe(true);+ });++ it("keeps the menu on editable fields", () => {+ document.body.innerHTML = `<div><input /><textarea></textarea>+ <div contenteditable="true"></div></div>`;+ expect(dispatchContextMenu(document.querySelector("input")!)).toBe(false);+ expect(dispatchContextMenu(document.querySelector("textarea")!)).toBe(+ false,+ );+ expect(+ dispatchContextMenu(document.querySelector("[contenteditable]")!),+ ).toBe(false);+ });++ it("keeps the menu on selectable content areas", () => {+ document.body.innerHTML = `<div class="selectable"><p>message</p></div>+ <pre>log line</pre>+ <p><code>inline_code</code></p>`;+ expect(dispatchContextMenu(document.querySelector("p")!)).toBe(false);+ expect(dispatchContextMenu(document.querySelector("pre")!)).toBe(false);+ expect(dispatchContextMenu(document.querySelector("code")!)).toBe(false);+ });++ it("keeps the menu when a text selection exists", () => {+ document.body.innerHTML = `<div class="card"><span id="sel">selected text</span></div>`;+ const range = document.createRange();+ range.selectNodeContents(document.getElementById("sel")!);+ const selection = window.getSelection();+ selection?.removeAllRanges();+ selection?.addRange(range);+ try {+ expect(dispatchContextMenu(document.querySelector(".card")!)).toBe(false);+ } finally {+ selection?.removeAllRanges();+ }+ });+});