Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(desktop): show spelling suggestions in right-click menu (#9608)
JimmyChia8ffcc88dbdf1
diff --git a/apps/desktop/src/main/context-menu.test.ts b/apps/desktop/src/main/context-menu.test.tsindex b06b809165..11719e8067 100644--- a/apps/desktop/src/main/context-menu.test.ts+++ b/apps/desktop/src/main/context-menu.test.ts@@ -63,6 +63,8 @@ type ContextMenuParams = {linkURL: string;mediaType: string;hasImageContents: boolean;+ misspelledWord: string;+ dictionarySuggestions: string[];x: number;y: number;editFlags: {@@ -83,6 +85,8 @@ function makeWebContents() {const handlers: Listener[] = [];return {copyImageAt: vi.fn(),+ replaceMisspelling: vi.fn(),+ session: { addWordToSpellCheckerDictionary: vi.fn() },on(event: string, fn: Listener) {if (event === "context-menu") handlers.push(fn);},@@ -99,6 +103,45 @@ const baseEditFlags = {canSelectAll: false,};+describe("installContextMenu — spelling", () => {+ beforeEach(() => {+ ctx.capturedItems.length = 0;+ ctx.preferredLanguagesRef.current = ["en-US"];+ });++ it("shows suggestions and 'Add to Dictionary' first for a misspelled word in an editable field", () => {+ const wc = makeWebContents();+ installContextMenu(wc as never);+ wc.fire(+ baseSelection({+ isEditable: true,+ misspelledWord: "teh",+ dictionarySuggestions: ["the", "tea"],+ editFlags: { ...baseEditFlags, canPaste: true },+ }),+ );++ expect(lastMenuLabelsOrEmpty().slice(0, 3)).toEqual([+ "the",+ "tea",+ "Add to Dictionary",+ ]);+ invokeByLabel("the");+ expect(wc.replaceMisspelling).toHaveBeenCalledWith("the");+ invokeByLabel("Add to Dictionary");+ expect(wc.session.addWordToSpellCheckerDictionary).toHaveBeenCalledWith("teh");+ });++ it("omits spelling items when the field is not editable", () => {+ const wc = makeWebContents();+ installContextMenu(wc as never);+ wc.fire(+ baseSelection({ selectionText: "teh", misspelledWord: "teh", dictionarySuggestions: ["the"] }),+ );+ expect(lastMenuLabelsOrEmpty()).not.toContain("Add to Dictionary");+ });+});+describe("installContextMenu — link items", () => {beforeEach(() => {ctx.capturedItems.length = 0;@@ -255,6 +298,8 @@ function baseSelection(over: Partial<ContextMenuParams>): ContextMenuParams {linkURL: "",mediaType: "none",hasImageContents: false,+ misspelledWord: "",+ dictionarySuggestions: [],x: 0,y: 0,editFlags: { ...baseEditFlags },diff --git a/apps/desktop/src/main/context-menu.ts b/apps/desktop/src/main/context-menu.tsindex ff7ebaed1f..d63bef1d60 100644--- a/apps/desktop/src/main/context-menu.ts+++ b/apps/desktop/src/main/context-menu.ts@@ -28,6 +28,8 @@ export function installContextMenu(webContents: WebContents): void {linkURL,mediaType,hasImageContents,+ misspelledWord,+ dictionarySuggestions,} = params;const hasSelection = selectionText.trim().length > 0;// params.linkURL is the resolved absolute URL of the anchor under the@@ -43,6 +45,26 @@ export function installContextMenu(webContents: WebContents): void {const menu = new Menu();+ // Spelling: suggestions first, like Chrome. Only in editable fields.+ if (isEditable && misspelledWord) {+ for (const suggestion of dictionarySuggestions) {+ menu.append(+ new MenuItem({+ label: suggestion,+ click: () => webContents.replaceMisspelling(suggestion),+ }),+ );+ }+ menu.append(+ new MenuItem({+ label: labels.addToDictionary,+ click: () =>+ webContents.session.addWordToSpellCheckerDictionary(misspelledWord),+ }),+ );+ menu.append(new MenuItem({ type: "separator" }));+ }+if (isEditable && editFlags.canCut) {menu.append(new MenuItem({ role: "cut" }));}@@ -127,6 +149,7 @@ type ContextMenuLabels = {openLink: string;copyLinkAddress: string;copyImage: string;+ addToDictionary: string;};const labelsByLocale: Record<string, ContextMenuLabels> = {@@ -134,26 +157,31 @@ const labelsByLocale: Record<string, ContextMenuLabels> = {openLink: "Open Link in Browser",copyLinkAddress: "Copy Link Address",copyImage: "Copy Image",+ addToDictionary: "Add to Dictionary",},"zh-Hans": {openLink: "在浏览器中打开链接",copyLinkAddress: "复制链接地址",copyImage: "复制图片",+ addToDictionary: "添加到词典",},"zh-Hant": {openLink: "在瀏覽器中開啟連結",copyLinkAddress: "複製連結網址",copyImage: "複製圖片",+ addToDictionary: "加入字典",},ja: {openLink: "ブラウザでリンクを開く",copyLinkAddress: "リンクのアドレスをコピー",copyImage: "画像をコピー",+ addToDictionary: "辞書に追加",},ko: {openLink: "브라우저에서 링크 열기",copyLinkAddress: "링크 주소 복사",copyImage: "이미지 복사",+ addToDictionary: "사전에 추가",},};