Skip to content

Commit

Permalink
fix #132314.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Sep 23, 2021
1 parent 1ca0acf commit c8b2adb
Showing 1 changed file with 36 additions and 0 deletions.
Expand Up @@ -282,6 +282,38 @@ export class NotebookClipboardContribution extends Disposable {
};
}

private _focusInsideEmebedMonaco(editor: INotebookEditor) {
const windowSelection = window.getSelection();

if (windowSelection?.rangeCount !== 1) {
return false;
}

const activeSelection = windowSelection.getRangeAt(0);
if (activeSelection.startContainer === activeSelection.endContainer && activeSelection.endOffset - activeSelection.startOffset === 0) {
return false;
}

let container: any = activeSelection.commonAncestorContainer;
const body = editor.getDomNode();

if (!body.contains(container)) {
return false;
}

while (container
&&
container !== body) {
if ((container as HTMLElement).classList && (container as HTMLElement).classList.contains('monaco-editor')) {
return true;
}

container = container.parentNode;
}

return false;
}

runCopyAction(accessor: ServicesAccessor) {
const activeElement = <HTMLElement>document.activeElement;
if (activeElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) {
Expand All @@ -293,6 +325,10 @@ export class NotebookClipboardContribution extends Disposable {
return false;
}

if (this._focusInsideEmebedMonaco(editor)) {
return false;
}

return runCopyCells(accessor, editor, undefined);
}

Expand Down

0 comments on commit c8b2adb

Please sign in to comment.