Skip to content

making sure the then on triggerPaste is not evaluated twice#284961

Merged
aiday-mar merged 1 commit intomainfrom
few-cardinal
Dec 24, 2025
Merged

making sure the then on triggerPaste is not evaluated twice#284961
aiday-mar merged 1 commit intomainfrom
few-cardinal

Conversation

@aiday-mar
Copy link
Contributor

@aiday-mar aiday-mar commented Dec 24, 2025

fixes #284848

Copilot AI review requested due to automatic review settings December 24, 2025 14:18
@aiday-mar aiday-mar self-assigned this Dec 24, 2025
@aiday-mar aiday-mar enabled auto-merge (squash) December 24, 2025 14:19
@vs-code-engineering vs-code-engineering bot added this to the December / January 2026 milestone Dec 24, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where the then handler on triggerPaste is evaluated multiple times, causing duplicate paste operations. The fix introduces a lock mechanism to prevent the handler from executing more than once.

  • Adds a new electronBugWorkaroundPasteEventLock flag to PasteOptions
  • Implements a check-and-set lock pattern to guard against duplicate handler invocation
  • Adds explanatory comments describing the issue

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/vs/editor/browser/controller/editContext/clipboardUtils.ts Adds the electronBugWorkaroundPasteEventLock boolean field to the PasteOptions object
src/vs/editor/contrib/clipboard/browser/clipboard.ts Implements the lock pattern by initializing the lock to false, checking it before executing the paste handler, and setting it to true after the first execution to prevent duplicate runs

Comment on lines 321 to +324
const triggerPaste = clipboardService.triggerPaste(getActiveWindow().vscodeWindowId);
if (triggerPaste) {
logService.trace('registerExecCommandImpl (triggerPaste defined)');
PasteOptions.electronBugWorkaroundPasteEventLock = false;
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lock initialization at line 324 is confusing because it happens outside the promise chain, making the code flow harder to follow. For consistency with the existing pattern used for electronBugWorkaroundPasteEventHasFired (line 320), consider moving the lock initialization to line 320 as well. This would make it clearer that both flags are reset before triggerPaste is invoked, rather than having one reset before and one reset after the promise is created.

Suggested change
const triggerPaste = clipboardService.triggerPaste(getActiveWindow().vscodeWindowId);
if (triggerPaste) {
logService.trace('registerExecCommandImpl (triggerPaste defined)');
PasteOptions.electronBugWorkaroundPasteEventLock = false;
PasteOptions.electronBugWorkaroundPasteEventLock = false;
const triggerPaste = clipboardService.triggerPaste(getActiveWindow().vscodeWindowId);
if (triggerPaste) {
logService.trace('registerExecCommandImpl (triggerPaste defined)');

Copilot uses AI. Check for mistakes.
Comment on lines +327 to +329
// 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
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment's wording could be clearer. Consider revising to: "Ensure this doesn't run twice. What appears to be happening is that triggerPaste is called once but its handler is called multiple times when the issue reproduces." This improves readability by fixing the typo, adding proper punctuation, and clarifying the sentence structure.

Suggested change
// 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
// Ensure this doesn't run twice. What appears to be happening is that
// triggerPaste is called once but its handler is called multiple times
// when the issue reproduces.

Copilot uses AI. Check for mistakes.
@aiday-mar aiday-mar merged commit 5d2a6f8 into main Dec 24, 2025
33 of 34 checks passed
@aiday-mar aiday-mar deleted the few-cardinal branch December 24, 2025 16:56
alexdima added a commit that referenced this pull request Jan 8, 2026
alexdima added a commit that referenced this pull request Jan 8, 2026
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Feb 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ctrl+v is pasting twice sometimes

3 participants