fix(desktop): paste as text no longer doubles the pasted text (#11958)
Co-authored-by: Antony <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
This commit is contained in:
2 files changed
+42
-1
No files matched your search
@@ -183,6 +183,37 @@ describe("DesktopApplicationMenu", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
// Chromium pastes as plain text for the accelerator on its own. Dispatching
|
||||
// the action as well injects a second paste, which doubles the pasted text.
|
||||
it.effect("leaves the accelerator to Chromium instead of injecting a paste", () =>
|
||||
Effect.gen(function* () {
|
||||
const selectedAction = yield* Deferred.make<string>();
|
||||
const applicationMenuTemplate =
|
||||
yield* Deferred.make<readonly Electron.MenuItemConstructorOptions[]>();
|
||||
|
||||
yield* configureMenu(selectedAction, applicationMenuTemplate);
|
||||
|
||||
const template = yield* Deferred.await(applicationMenuTemplate);
|
||||
const editMenu = template.find((item) => item.label === "Edit");
|
||||
if (!Array.isArray(editMenu?.submenu)) {
|
||||
throw new Error("Expected Edit menu submenu to be an array.");
|
||||
}
|
||||
const pasteAsTextItem = editMenu.submenu.find((item) => item.label === "Paste as Text");
|
||||
if (typeof pasteAsTextItem?.click !== "function") {
|
||||
throw new Error("Expected Paste as Text menu item to have a click handler.");
|
||||
}
|
||||
|
||||
pasteAsTextItem.click(
|
||||
{} as Electron.MenuItem,
|
||||
{} as Electron.BrowserWindow,
|
||||
{
|
||||
triggeredByAccelerator: true,
|
||||
} as unknown as KeyboardEvent,
|
||||
);
|
||||
assert.isFalse(yield* Deferred.isDone(selectedAction));
|
||||
}),
|
||||
);
|
||||
|
||||
// Zoom must route through DesktopWindow.zoomMain instead of the Electron
|
||||
// zoom roles: the roles zoom whichever webContents has focus, which breaks
|
||||
// app zoom while an embedded preview WebContentsView holds focus.
|
||||
|
||||
@@ -137,7 +137,17 @@ export const make = Effect.gen(function* () {
|
||||
const settingsClick = () => {
|
||||
runMenuEffect("open-settings", dispatchMenuAction("open-settings"));
|
||||
};
|
||||
const pasteAsTextClick = () => {
|
||||
// Chromium already pastes as plain text for this chord, so the accelerator
|
||||
// needs nothing from the menu: the composer and the terminal each arm
|
||||
// themselves from the same keydown. Routing it through the renderer anyway
|
||||
// lands a second, injected paste and doubles the text. Only a menu click,
|
||||
// which produces no keystroke for them to see, needs that round trip.
|
||||
const pasteAsTextClick = (
|
||||
_item: Electron.MenuItem,
|
||||
_window: Electron.BaseWindow | undefined,
|
||||
event: Electron.KeyboardEvent,
|
||||
) => {
|
||||
if (event.triggeredByAccelerator === true) return;
|
||||
runMenuEffect("paste-as-text", dispatchMenuAction("paste-as-text"));
|
||||
};
|
||||
const zoomClick = (direction: DesktopWindow.MainWindowZoomDirection) => () => {
|
||||
|
||||
Reference in new issue
Block a user