From 5d2a6f896dbf5b369bb6f875ba618bcea5890781 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Wed, 24 Dec 2025 17:56:26 +0100 Subject: [PATCH] making sure the then on triggerPaste is not evaluated twice (#284961) making sure the then is not evaluated twice --- .../browser/controller/editContext/clipboardUtils.ts | 3 ++- src/vs/editor/contrib/clipboard/browser/clipboard.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/vs/editor/browser/controller/editContext/clipboardUtils.ts b/src/vs/editor/browser/controller/editContext/clipboardUtils.ts index 8b3b0838d40..3402910c3f2 100644 --- a/src/vs/editor/browser/controller/editContext/clipboardUtils.ts +++ b/src/vs/editor/browser/controller/editContext/clipboardUtils.ts @@ -168,7 +168,8 @@ export const CopyOptions = { }; export const PasteOptions = { - electronBugWorkaroundPasteEventHasFired: false + electronBugWorkaroundPasteEventHasFired: false, + electronBugWorkaroundPasteEventLock: false }; interface InMemoryClipboardMetadata { diff --git a/src/vs/editor/contrib/clipboard/browser/clipboard.ts b/src/vs/editor/contrib/clipboard/browser/clipboard.ts index 9fa2c86b4b5..735d4698f00 100644 --- a/src/vs/editor/contrib/clipboard/browser/clipboard.ts +++ b/src/vs/editor/contrib/clipboard/browser/clipboard.ts @@ -321,8 +321,16 @@ if (PasteAction) { const triggerPaste = clipboardService.triggerPaste(getActiveWindow().vscodeWindowId); if (triggerPaste) { logService.trace('registerExecCommandImpl (triggerPaste defined)'); + PasteOptions.electronBugWorkaroundPasteEventLock = false; return triggerPaste.then(async () => { if (PasteOptions.electronBugWorkaroundPasteEventHasFired === false) { + // Ensure this doesn't run twice, what appears to be happening is + // triggerPasteis called once but it's handler is called multiple times + // when it reproduces + if (PasteOptions.electronBugWorkaroundPasteEventLock === true) { + return; + } + PasteOptions.electronBugWorkaroundPasteEventLock = true; return pasteWithNavigatorAPI(focusedEditor, clipboardService, logService); } logService.trace('registerExecCommandImpl (after triggerPaste)');