From 7d729bbcc8340a6a0b129e915acbf0435cf3c37a Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 14 Jun 2022 15:37:47 -0700 Subject: [PATCH] Disable copy/paste actions if editor is not focused (#152125) This fixes copy/paste triggering when you copy/paste in the rename widget for example --- .../contrib/copyPaste/browser/copyPasteController.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/vs/editor/contrib/copyPaste/browser/copyPasteController.ts b/src/vs/editor/contrib/copyPaste/browser/copyPasteController.ts index 8710f815764..9c57b947d82 100644 --- a/src/vs/editor/contrib/copyPaste/browser/copyPasteController.ts +++ b/src/vs/editor/contrib/copyPaste/browser/copyPasteController.ts @@ -34,9 +34,7 @@ const defaultPasteEditProvider = new class implements DocumentPasteEditProvider const textDataTransfer = dataTransfer.get(Mimes.text) ?? dataTransfer.get('text'); if (textDataTransfer) { const text = await textDataTransfer.asString(); - return { - insertText: text - }; + return { insertText: text }; } return undefined; @@ -82,7 +80,7 @@ export class CopyPasteController extends Disposable implements IEditorContributi } private handleCopy(e: ClipboardEvent) { - if (!e.clipboardData) { + if (!e.clipboardData || !this._editor.hasTextFocus()) { return; } @@ -126,8 +124,12 @@ export class CopyPasteController extends Disposable implements IEditorContributi } private async handlePaste(e: ClipboardEvent) { + if (!e.clipboardData || !this._editor.hasTextFocus()) { + return; + } + const selections = this._editor.getSelections(); - if (!e.clipboardData || !selections?.length || !this._editor.hasModel()) { + if (!selections?.length || !this._editor.hasModel()) { return; }