diff --git a/src/sql/workbench/parts/notebook/browser/cellViews/code.component.ts b/src/sql/workbench/parts/notebook/browser/cellViews/code.component.ts index 361234e04a..b0722466ce 100644 --- a/src/sql/workbench/parts/notebook/browser/cellViews/code.component.ts +++ b/src/sql/workbench/parts/notebook/browser/cellViews/code.component.ts @@ -305,7 +305,9 @@ export class CodeComponent extends AngularDisposable implements OnInit, OnChange } private setFocusAndScroll(): void { - if (this.cellModel.id === this._activeCellId) { + // If offsetParent is null, the element isn't visible + // In this case, we don't want a cell to grab focus for an editor that isn't in the foreground + if (this.cellModel.id === this._activeCellId && this._editor.getContainer().offsetParent) { this._editor.focus(); this._editor.getContainer().scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } diff --git a/src/sql/workbench/parts/notebook/browser/cellViews/outputArea.component.ts b/src/sql/workbench/parts/notebook/browser/cellViews/outputArea.component.ts index 729af6bdd3..e28b2b8dc3 100644 --- a/src/sql/workbench/parts/notebook/browser/cellViews/outputArea.component.ts +++ b/src/sql/workbench/parts/notebook/browser/cellViews/outputArea.component.ts @@ -54,7 +54,9 @@ export class OutputAreaComponent extends AngularDisposable implements OnInit { } private setFocusAndScroll(node: HTMLElement): void { - if (node) { + // If offsetParent is null, the element isn't visible + // In this case, we don't want a cell to grab focus for an editor that isn't in the foreground + if (node && node.offsetParent) { node.focus(); node.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); }