From 8b543d1d125cf93a2cdeda88dd603e785d611e33 Mon Sep 17 00:00:00 2001 From: Barbara Valdez <34872381+barbaravaldez@users.noreply.github.com> Date: Wed, 2 Mar 2022 16:57:37 -0800 Subject: [PATCH] check find widget is not focused (#18506) * remove logic to check that the find widget is visible --- .../notebook/browser/notebook.component.ts | 66 +++++++++---------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/notebook.component.ts b/src/sql/workbench/contrib/notebook/browser/notebook.component.ts index 7fc03d89c9..2ec125367b 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebook.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebook.component.ts @@ -141,54 +141,50 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe // on its elements (we have a "virtual" focus that is updated as users click or navigate through cells). So some of the keyboard // events we care about are fired when the document focus is on something else - typically the root window. this._register(DOM.addDisposableListener(window, DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => { - // For DownArrow, UpArrow and Enter - Make sure that the current active element is an ancestor - this is to prevent us from handling events when the focus is + // For DownArrow, UpArrow, Enter, Escape (unselecting active cell) - Make sure that the current active element is an ancestor - this is to prevent us from handling events when the focus is // on some other dialog or part of the app. - // For Escape - the focused element is the div.notebook-preview or textarea.inputarea of the cell, so we need to make sure that it is a descendant of the current active cell + // For Escape (exiting edit mode)- the focused element is the div.notebook-preview or textarea.inputarea of the cell, so we need to make sure that it is a descendant of the current active cell // on the current active editor. const activeCellElement = this.container.nativeElement.querySelector(`.editor-group-container.active .notebook-cell.active`); - const findWidgetVisible = !!document.querySelector(`.editor-widget.find-widget.visible`); let handled = false; - // check that the find widget is not opened before handling notebook cell events - if (!findWidgetVisible) { - if (DOM.isAncestor(this.container.nativeElement, document.activeElement) && this.isActive() && this.model.activeCell) { - const event = new StandardKeyboardEvent(e); - if (!this.model.activeCell?.isEditMode) { - if (event.keyCode === KeyCode.DownArrow) { - let next = (this.findCellIndex(this.model.activeCell) + 1) % this.cells.length; + if (DOM.isAncestor(this.container.nativeElement, document.activeElement) && this.isActive() && this.model.activeCell) { + const event = new StandardKeyboardEvent(e); + if (!this.model.activeCell?.isEditMode) { + if (event.keyCode === KeyCode.DownArrow) { + let next = (this.findCellIndex(this.model.activeCell) + 1) % this.cells.length; - this.navigateToCell(this.cells[next]); - handled = true; - } else if (event.keyCode === KeyCode.UpArrow) { - let index = this.findCellIndex(this.model.activeCell); - if (index === 0) { - index = this.cells.length; - } - this.navigateToCell(this.cells[--index]); - handled = true; - } - else if (event.keyCode === KeyCode.Enter) { - this.toggleEditMode(); - handled = true; - } - else if (event.keyCode === KeyCode.Escape) { - // unselects active cell and removes the focus from code cells - this.unselectActiveCell(); - (document.activeElement as HTMLElement).blur(); - handled = true; + this.navigateToCell(this.cells[next]); + handled = true; + } else if (event.keyCode === KeyCode.UpArrow) { + let index = this.findCellIndex(this.model.activeCell); + if (index === 0) { + index = this.cells.length; } + this.navigateToCell(this.cells[--index]); + handled = true; } - } else if (DOM.isAncestor(document.activeElement, activeCellElement) && this.isActive() && this.model.activeCell) { - const event = new StandardKeyboardEvent(e); - if (event.keyCode === KeyCode.Escape) { - // first time hitting escape removes the cursor from code cell and changes toolbar in text cells and changes edit mode to false + else if (event.keyCode === KeyCode.Enter) { this.toggleEditMode(); handled = true; } + else if (event.keyCode === KeyCode.Escape) { + // unselects active cell and removes the focus from code cells + this.unselectActiveCell(); + (document.activeElement as HTMLElement).blur(); + handled = true; + } } - if (handled) { - DOM.EventHelper.stop(e); + } else if (DOM.isAncestor(document.activeElement, activeCellElement) && this.isActive() && this.model.activeCell) { + const event = new StandardKeyboardEvent(e); + if (event.keyCode === KeyCode.Escape) { + // first time hitting escape removes the cursor from code cell and changes toolbar in text cells and changes edit mode to false + this.toggleEditMode(); + handled = true; } } + if (handled) { + DOM.EventHelper.stop(e); + } })); this._register(this.themeService.onDidColorThemeChange(this.updateTheme, this)); this.updateTheme(this.themeService.getColorTheme());