@@ -14,7 +14,7 @@ import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextke
1414import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js' ;
1515import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js' ;
1616import { ILogService } from '../../../../platform/log/common/log.js' ;
17- import { CopyOptions , generateDataToCopyAndStoreInMemory , InMemoryClipboardMetadataManager , PasteOptions } from '../../../browser/controller/editContext/clipboardUtils.js' ;
17+ import { CopyOptions , generateDataToCopyAndStoreInMemory , InMemoryClipboardMetadataManager } from '../../../browser/controller/editContext/clipboardUtils.js' ;
1818import { NativeEditContextRegistry } from '../../../browser/controller/editContext/native/nativeEditContextRegistry.js' ;
1919import { IActiveCodeEditor , ICodeEditor } from '../../../browser/editorBrowser.js' ;
2020import { Command , EditorAction , MultiCommand , registerEditorAction } from '../../../browser/editorExtensions.js' ;
@@ -208,28 +208,6 @@ function executeClipboardCopyWithWorkaround(editor: IActiveCodeEditor, clipboard
208208 }
209209}
210210
211- async function pasteWithNavigatorAPI ( editor : IActiveCodeEditor , clipboardService : IClipboardService , logService : ILogService ) : Promise < void > {
212- const clipboardText = await clipboardService . readText ( ) ;
213- if ( clipboardText !== '' ) {
214- const metadata = InMemoryClipboardMetadataManager . INSTANCE . get ( clipboardText ) ;
215- let pasteOnNewLine = false ;
216- let multicursorText : string [ ] | null = null ;
217- let mode : string | null = null ;
218- if ( metadata ) {
219- pasteOnNewLine = ( editor . getOption ( EditorOption . emptySelectionClipboard ) && ! ! metadata . isFromEmptySelection ) ;
220- multicursorText = ( typeof metadata . multicursorText !== 'undefined' ? metadata . multicursorText : null ) ;
221- mode = metadata . mode ;
222- }
223- logService . trace ( 'pasteWithNavigatorAPI with id : ' , metadata ?. id , ', clipboardText.length : ' , clipboardText . length ) ;
224- editor . trigger ( 'keyboard' , Handler . Paste , {
225- text : clipboardText ,
226- pasteOnNewLine,
227- multicursorText,
228- mode
229- } ) ;
230- }
231- }
232-
233211function registerExecCommandImpl ( target : MultiCommand | undefined , browserCommand : 'cut' | 'copy' ) : void {
234212 if ( ! target ) {
235213 return ;
@@ -317,25 +295,10 @@ if (PasteAction) {
317295 }
318296
319297 logService . trace ( 'registerExecCommandImpl (before triggerPaste)' ) ;
320- PasteOptions . electronBugWorkaroundPasteEventHasFired = false ;
321- logService . trace ( '(before triggerPaste) PasteOptions.electronBugWorkaroundPasteEventHasFired : ' , PasteOptions . electronBugWorkaroundPasteEventHasFired ) ;
322298 const triggerPaste = clipboardService . triggerPaste ( getActiveWindow ( ) . vscodeWindowId ) ;
323299 if ( triggerPaste ) {
324300 logService . trace ( 'registerExecCommandImpl (triggerPaste defined)' ) ;
325- PasteOptions . electronBugWorkaroundPasteEventLock = false ;
326301 return triggerPaste . then ( async ( ) => {
327- logService . trace ( '(triggerPaste) PasteOptions.electronBugWorkaroundPasteEventHasFired : ' , PasteOptions . electronBugWorkaroundPasteEventHasFired ) ;
328- if ( PasteOptions . electronBugWorkaroundPasteEventHasFired === false ) {
329- // Ensure this doesn't run twice, what appears to be happening is
330- // triggerPasteis called once but it's handler is called multiple times
331- // when it reproduces
332- logService . trace ( '(triggerPaste) PasteOptions.electronBugWorkaroundPasteEventLock : ' , PasteOptions . electronBugWorkaroundPasteEventLock ) ;
333- if ( PasteOptions . electronBugWorkaroundPasteEventLock === true ) {
334- return ;
335- }
336- PasteOptions . electronBugWorkaroundPasteEventLock = true ;
337- return pasteWithNavigatorAPI ( focusedEditor , clipboardService , logService ) ;
338- }
339302 logService . trace ( 'registerExecCommandImpl (after triggerPaste)' ) ;
340303 return CopyPasteController . get ( focusedEditor ) ?. finishedPaste ( ) ?? Promise . resolve ( ) ;
341304 } ) ;
@@ -345,7 +308,27 @@ if (PasteAction) {
345308 if ( platform . isWeb ) {
346309 logService . trace ( 'registerExecCommandImpl (Paste handling on web)' ) ;
347310 // Use the clipboard service if document.execCommand('paste') was not successful
348- return pasteWithNavigatorAPI ( focusedEditor , clipboardService , logService ) ;
311+ return ( async ( ) => {
312+ const clipboardText = await clipboardService . readText ( ) ;
313+ if ( clipboardText !== '' ) {
314+ const metadata = InMemoryClipboardMetadataManager . INSTANCE . get ( clipboardText ) ;
315+ let pasteOnNewLine = false ;
316+ let multicursorText : string [ ] | null = null ;
317+ let mode : string | null = null ;
318+ if ( metadata ) {
319+ pasteOnNewLine = ( focusedEditor . getOption ( EditorOption . emptySelectionClipboard ) && ! ! metadata . isFromEmptySelection ) ;
320+ multicursorText = ( typeof metadata . multicursorText !== 'undefined' ? metadata . multicursorText : null ) ;
321+ mode = metadata . mode ;
322+ }
323+ logService . trace ( 'registerExecCommandImpl (clipboardText.length : ' , clipboardText . length , ' id : ' , metadata ?. id , ')' ) ;
324+ focusedEditor . trigger ( 'keyboard' , Handler . Paste , {
325+ text : clipboardText ,
326+ pasteOnNewLine,
327+ multicursorText,
328+ mode
329+ } ) ;
330+ }
331+ } ) ( ) ;
349332 }
350333 return true ;
351334 }
0 commit comments