WORKAROUND - paste fix - using readText from navigator API when triggerPaste fails#283571
WORKAROUND - paste fix - using readText from navigator API when triggerPaste fails#283571
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements a fallback mechanism for paste operations when triggerPaste fails, mirroring the existing workaround for copy operations. The change refactors paste handling logic across multiple editor contexts and introduces a flag-based detection system to determine when the clipboard paste event doesn't fire properly.
Key Changes
- Adds
pasteWithNavigatorAPIfunction as a fallback whentriggerPastedoesn't fire paste events - Refactors common paste data processing logic into reusable utility functions (
computePasteDataandgetPasteDataFromMetadata) - Introduces
PasteOptions.electronBugWorkaroundPasteEventHasFiredflag to detect when paste events fail to fire
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/vs/editor/contrib/clipboard/browser/clipboard.ts | Adds pasteWithNavigatorAPI fallback function and integrates it into paste command handling with workaround flag check |
| src/vs/editor/browser/controller/editContext/clipboardUtils.ts | Introduces IPasteData interface, computePasteData, getPasteDataFromMetadata utility functions, and PasteOptions flag |
| src/vs/editor/browser/controller/editContext/textArea/textAreaEditContextInput.ts | Refactors paste event handling to use new utility functions and moves IPasteData interface to clipboardUtils |
| src/vs/editor/browser/controller/editContext/textArea/textAreaEditContext.ts | Simplifies paste event handler by using pre-computed IPasteData fields and removes duplicate _emptySelectionClipboard field |
| src/vs/editor/browser/controller/editContext/native/nativeEditContext.ts | Refactors paste event handling to use computePasteData utility function |
| if (!PasteOptions.electronBugWorkaroundPasteEventHasFired) { | ||
| return pasteWithNavigatorAPI(focusedEditor, clipboardService, logService); | ||
| } |
There was a problem hiding this comment.
The PasteOptions.electronBugWorkaroundPasteEventHasFired flag is never reset to false before checking it. Unlike the copy workaround pattern (see line 203 where CopyOptions.electronBugWorkaroundCopyEventHasFired is reset before execCommand('copy')), this flag remains true after the first paste event, causing all subsequent paste operations via triggerPaste to incorrectly fall back to the Navigator API even when the paste event fires successfully. The flag should be reset to false before calling clipboardService.triggerPaste() at line 326.
| } | ||
| } | ||
|
|
||
| async function pasteWithNavigatorAPI(editor: IActiveCodeEditor, clipboardService: IClipboardService, logService: ILogService): Promise<void> { |
There was a problem hiding this comment.
The function name pasteWithNavigatorAPI is inconsistent with the actual implementation. The function uses clipboardService.readText() which is an abstraction that may or may not use the Navigator API depending on the platform. A more accurate name would be pasteFromClipboardService or pasteWithFallback to reflect that it's using the clipboard service abstraction rather than directly calling the Navigator API.
| async function pasteWithNavigatorAPI(editor: IActiveCodeEditor, clipboardService: IClipboardService, logService: ILogService): Promise<void> { | |
| async function pasteFromClipboardService(editor: IActiveCodeEditor, clipboardService: IClipboardService, logService: ILogService): Promise<void> { |
using readText from navigator API when triggerPaste fails
counterpart to copy issue