Skip to content

Commit 96bddf8

Browse files
TonybynMp4Ynaugtclaude
authored
fix(desktop): paste as text no longer doubles the pasted text (pingdotgg#11958)
Co-authored-by: Antony <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
1 parent b18a560 commit 96bddf8

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎apps/desktop/src/window/DesktopApplicationMenu.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,37 @@ describe("DesktopApplicationMenu", () => {
183183
}),
184184
);
185185

186+
// Chromium pastes as plain text for the accelerator on its own. Dispatching
187+
// the action as well injects a second paste, which doubles the pasted text.
188+
it.effect("leaves the accelerator to Chromium instead of injecting a paste", () =>
189+
Effect.gen(function* () {
190+
const selectedAction = yield* Deferred.make<string>();
191+
const applicationMenuTemplate =
192+
yield* Deferred.make<readonly Electron.MenuItemConstructorOptions[]>();
193+
194+
yield* configureMenu(selectedAction, applicationMenuTemplate);
195+
196+
const template = yield* Deferred.await(applicationMenuTemplate);
197+
const editMenu = template.find((item) => item.label === "Edit");
198+
if (!Array.isArray(editMenu?.submenu)) {
199+
throw new Error("Expected Edit menu submenu to be an array.");
200+
}
201+
const pasteAsTextItem = editMenu.submenu.find((item) => item.label === "Paste as Text");
202+
if (typeof pasteAsTextItem?.click !== "function") {
203+
throw new Error("Expected Paste as Text menu item to have a click handler.");
204+
}
205+
206+
pasteAsTextItem.click(
207+
{} as Electron.MenuItem,
208+
{} as Electron.BrowserWindow,
209+
{
210+
triggeredByAccelerator: true,
211+
} as unknown as KeyboardEvent,
212+
);
213+
assert.isFalse(yield* Deferred.isDone(selectedAction));
214+
}),
215+
);
216+
186217
// Zoom must route through DesktopWindow.zoomMain instead of the Electron
187218
// zoom roles: the roles zoom whichever webContents has focus, which breaks
188219
// app zoom while an embedded preview WebContentsView holds focus.

‎apps/desktop/src/window/DesktopApplicationMenu.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,17 @@ export const make = Effect.gen(function* () {
137137
const settingsClick = () => {
138138
runMenuEffect("open-settings", dispatchMenuAction("open-settings"));
139139
};
140-
const pasteAsTextClick = () => {
140+
// Chromium already pastes as plain text for this chord, so the accelerator
141+
// needs nothing from the menu: the composer and the terminal each arm
142+
// themselves from the same keydown. Routing it through the renderer anyway
143+
// lands a second, injected paste and doubles the text. Only a menu click,
144+
// which produces no keystroke for them to see, needs that round trip.
145+
const pasteAsTextClick = (
146+
_item: Electron.MenuItem,
147+
_window: Electron.BaseWindow | undefined,
148+
event: Electron.KeyboardEvent,
149+
) => {
150+
if (event.triggeredByAccelerator === true) return;
141151
runMenuEffect("paste-as-text", dispatchMenuAction("paste-as-text"));
142152
};
143153
const zoomClick = (direction: DesktopWindow.MainWindowZoomDirection) => () => {

0 commit comments

Comments
 (0)