Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(desktop): add right-click context menu with clipboard actions (#1575)

Jiayuan Zhang5e51f5b356c5
diff --git a/apps/desktop/src/main/context-menu.ts b/apps/desktop/src/main/context-menu.ts
new file mode 100644
index 0000000000..437b315b82
--- /dev/null
+++ b/apps/desktop/src/main/context-menu.ts
@@ -0,0 +1,33 @@
+import { BrowserWindow, Menu, MenuItem, type WebContents } from "electron";
+
+// Electron ships with no default right-click menu, so a user selecting text
+// in the renderer has no way to copy it. Mirror Chrome's minimal clipboard
+// menu using `roles`, which keeps i18n + accelerator handling native.
+export function installContextMenu(webContents: WebContents): void {
+ webContents.on("context-menu", (_event, params) => {
+ const { editFlags, selectionText, isEditable } = params;
+ const hasSelection = selectionText.trim().length > 0;
+
+ const menu = new Menu();
+
+ if (isEditable && editFlags.canCut) {
+ menu.append(new MenuItem({ role: "cut" }));
+ }
+ if (hasSelection && editFlags.canCopy) {
+ menu.append(new MenuItem({ role: "copy" }));
+ }
+ if (isEditable && editFlags.canPaste) {
+ menu.append(new MenuItem({ role: "paste" }));
+ }
+ if (isEditable && editFlags.canSelectAll) {
+ if (menu.items.length > 0) {
+ menu.append(new MenuItem({ type: "separator" }));
+ }
+ menu.append(new MenuItem({ role: "selectAll" }));
+ }
+
+ if (menu.items.length === 0) return;
+ const window = BrowserWindow.fromWebContents(webContents) ?? undefined;
+ menu.popup({ window });
+ });
+}
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index 1b22f4f4d5..970cafcde0 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -6,6 +6,7 @@ import fixPath from "fix-path";
import { setupAutoUpdater } from "./updater";
import { setupDaemonManager } from "./daemon-manager";
import { openExternalSafely } from "./external-url";
+import { installContextMenu } from "./context-menu";
// Bundled icon used for dev-mode dock/taskbar branding. In production the
// app bundle icon (from electron-builder) wins; this path is only consumed
@@ -109,6 +110,8 @@ function createWindow(): void {
return { action: "deny" };
});
+ installContextMenu(mainWindow.webContents);
+
if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
mainWindow.loadURL(process.env["ELECTRON_RENDERER_URL"]);
} else {