Skip to content

Commit

Permalink
Don't enable notebook copy if active element is not in the notebook d…
Browse files Browse the repository at this point in the history
…om (#202035)

Fixes #201178

Fixes copying text from the chat window when a notebook editor is active
  • Loading branch information
mjbvz authored Jan 8, 2024
1 parent d2a0272 commit 7452aaa
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -343,8 +343,8 @@ export class NotebookClipboardContribution extends Disposable {
runCopyAction(accessor: ServicesAccessor) {
const loggerService = accessor.get(ILogService);

const activeElement = <HTMLElement>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;
}
Expand All @@ -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;
Expand Down

0 comments on commit 7452aaa

Please sign in to comment.