From 7452aaa51d440d39c4e6ab61970b290b8600f52f Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 8 Jan 2024 14:31:37 -0800 Subject: [PATCH] Don't enable notebook copy if active element is not in the notebook dom (#202035) Fixes #201178 Fixes copying text from the chat window when a notebook editor is active --- .../browser/contrib/clipboard/notebookClipboard.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.ts b/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.ts index 694b84d87ee93..47b68f9f10bca 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.ts @@ -30,7 +30,7 @@ import { Categories } from 'vs/platform/action/common/actionCommonCategories'; import { ILogService } from 'vs/platform/log/common/log'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { showWindowLogActionId } from 'vs/workbench/services/log/common/logConstants'; -import { getActiveElement, getWindow } from 'vs/base/browser/dom'; +import { getActiveElement, getWindow, isAncestor } from 'vs/base/browser/dom'; let _logging: boolean = false; function toggleLogging() { @@ -343,8 +343,8 @@ export class NotebookClipboardContribution extends Disposable { runCopyAction(accessor: ServicesAccessor) { const loggerService = accessor.get(ILogService); - const activeElement = getActiveElement(); - if (activeElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) { + const activeElement = getActiveElement(); + if (activeElement instanceof HTMLElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) { _log(loggerService, '[NotebookEditor] focus is on input or textarea element, bypass'); return false; } @@ -355,6 +355,11 @@ export class NotebookClipboardContribution extends Disposable { return false; } + if (!isAncestor(activeElement, editor.getDomNode())) { + _log(loggerService, '[NotebookEditor] focus is outside of the notebook editor, bypass'); + return false; + } + if (this._focusInsideEmebedMonaco(editor)) { _log(loggerService, '[NotebookEditor] focus is on embed monaco editor, bypass'); return false;