Fix not resetting cell list focus context key when closing notebook

This commit is contained in:
Rob Lourens 2020-07-21 11:42:01 -07:00
parent 282214a364
commit 145a0072d3
2 changed files with 3 additions and 22 deletions

View file

@ -28,7 +28,7 @@ import { registerThemingParticipant } from 'vs/platform/theme/common/themeServic
import { EditorMemento } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorOptions, IEditorMemento } from 'vs/workbench/common/editor';
import { CELL_MARGIN, CELL_RUN_GUTTER, EDITOR_BOTTOM_PADDING, EDITOR_TOP_MARGIN, EDITOR_TOP_PADDING, SCROLLABLE_ELEMENT_PADDING_TOP, BOTTOM_CELL_TOOLBAR_HEIGHT, CELL_BOTTOM_MARGIN, CODE_CELL_LEFT_MARGIN } from 'vs/workbench/contrib/notebook/browser/constants';
import { CellEditState, CellFocusMode, ICellRange, ICellViewModel, INotebookCellList, INotebookEditor, INotebookEditorContribution, INotebookEditorMouseEvent, NotebookLayoutInfo, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_HAS_MULTIPLE_KERNELS, NOTEBOOK_OUTPUT_FOCUSED, INotebookDeltaDecoration, NOTEBOOK_CELL_LIST_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellEditState, CellFocusMode, ICellRange, ICellViewModel, INotebookCellList, INotebookEditor, INotebookEditorContribution, INotebookEditorMouseEvent, NotebookLayoutInfo, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_HAS_MULTIPLE_KERNELS, NOTEBOOK_OUTPUT_FOCUSED, INotebookDeltaDecoration } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookEditorExtensionsRegistry } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
import { NotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookCellList';
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/output/outputRenderer';
@ -86,9 +86,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
private _dimension: DOM.Dimension | null = null;
private _shadowElementViewInfo: { height: number, width: number, top: number; left: number; } | null = null;
private _cellListFocusTracker: DOM.IFocusTracker | null = null;
private _editorFocus: IContextKey<boolean> | null = null;
private _cellListFocus: IContextKey<boolean> | null = null;
private _outputFocus: IContextKey<boolean> | null = null;
private _editorEditable: IContextKey<boolean> | null = null;
private _editorRunnable: IContextKey<boolean> | null = null;
@ -239,12 +237,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
// Note - focus going to the webview will fire 'blur', but the webview element will be
// a descendent of the notebook editor root.
const focused = DOM.isAncestor(document.activeElement, this._overlayContainer);
if (focused) {
const cellListFocused = DOM.isAncestor(document.activeElement, this._body);
this._cellListFocus?.set(cellListFocused);
} else {
this._cellListFocus?.set(false);
}
this._editorFocus?.set(focused);
this._notebookViewModel?.setFocus(focused);
}
@ -265,7 +257,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
this._createBody(this._overlayContainer);
this._generateFontInfo();
this._editorFocus = NOTEBOOK_EDITOR_FOCUSED.bindTo(this.contextKeyService);
this._cellListFocus = NOTEBOOK_CELL_LIST_FOCUSED.bindTo(this.contextKeyService);
this._isVisible = true;
this._outputFocus = NOTEBOOK_OUTPUT_FOCUSED.bindTo(this.contextKeyService);
this._editorEditable = NOTEBOOK_EDITOR_EDITABLE.bindTo(this.contextKeyService);
@ -403,17 +394,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
this._register(widgetFocusTracker);
this._register(widgetFocusTracker.onDidFocus(() => this._onDidFocusEmitter.fire()));
this._cellListFocusTracker = this._register(DOM.trackFocus(this._body));
this._register(this._cellListFocusTracker.onDidFocus(() => {
// hack - FocusTracker forces 'blur' to run after 'focus'.
// We want the other way around so that when switching from notebook to notebook, the focus happens last
setTimeout(() => {
this.updateEditorFocus();
}, 0);
}));
this._register(this._cellListFocusTracker.onDidBlur(() => {
this.updateEditorFocus();
}));
}
private _updateForCursorNavigationMode(applyFocusChange: () => void): void {

View file

@ -19,7 +19,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IListService, IWorkbenchListOptions, WorkbenchList } from 'vs/platform/list/browser/listService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { CellRevealPosition, CellRevealType, CursorAtBoundary, getVisibleCells, ICellRange, ICellViewModel, INotebookCellList, reduceCellRanges, CellEditState, CellFocusMode, BaseCellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellRevealPosition, CellRevealType, CursorAtBoundary, getVisibleCells, ICellRange, ICellViewModel, INotebookCellList, reduceCellRanges, CellEditState, CellFocusMode, BaseCellRenderTemplate, NOTEBOOK_CELL_LIST_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellViewModel, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { diff, IProcessedOutput, NOTEBOOK_EDITOR_CURSOR_BOUNDARY, CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { clamp } from 'vs/base/common/numbers';
@ -75,6 +75,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
@IKeybindingService keybindingService: IKeybindingService
) {
super(listUser, container, delegate, renderers, options, contextKeyService, listService, themeService, configurationService, keybindingService);
NOTEBOOK_CELL_LIST_FOCUSED.bindTo(this.contextKeyService).set(true);
this._focusNextPreviousDelegate = options.focusNextPreviousDelegate;
this._previousFocusedElements = this.getFocusedElements();
this._localDisposableStore.add(this.onDidChangeFocus((e) => {