From b8976785fd0567a162eafc6a5153d841d4cf10ec Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Wed, 2 Oct 2019 11:56:57 -0700 Subject: [PATCH] Stop grabbing focus when nb editor isn't in view (#7466) * Stop grabbing focus when nb editor isn't in view * Add comments --- .../parts/notebook/browser/cellViews/code.component.ts | 4 +++- .../parts/notebook/browser/cellViews/outputArea.component.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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' }); }