From 9504dda6a717a0a0d45d992e21f2565f8a23f390 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Tue, 7 Jul 2020 17:48:28 -0700 Subject: [PATCH] Don't steal focus when restoring notebook editor state Fix #101622 --- .../browser/contrib/status/editorStatus.ts | 17 ++++++++--------- .../notebook/browser/notebookEditorWidget.ts | 4 ++-- .../notebook/browser/view/renderers/codeCell.ts | 4 ++-- .../browser/view/renderers/markdownCell.ts | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/status/editorStatus.ts b/src/vs/workbench/contrib/notebook/browser/contrib/status/editorStatus.ts index 7a41eec43b0..f8cef730906 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/status/editorStatus.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/status/editorStatus.ts @@ -3,15 +3,14 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { INotebookEditor, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_HAS_MULTIPLE_KERNELS } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; -import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { IQuickInputService, QuickPickInput, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput'; -import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; import * as nls from 'vs/nls'; -import { registerAction2, Action2, MenuId } from 'vs/platform/actions/common/actions'; -import { NOTEBOOK_ACTIONS_CATEGORY, INotebookCellActionContext } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions'; -import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; +import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; +import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput'; +import { INotebookCellActionContext, NOTEBOOK_ACTIONS_CATEGORY } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions'; +import { INotebookEditor, NOTEBOOK_HAS_MULTIPLE_KERNELS, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; +import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; registerAction2(class extends Action2 { @@ -20,11 +19,11 @@ registerAction2(class extends Action2 { id: 'notebook.selectKernel', category: NOTEBOOK_ACTIONS_CATEGORY, title: nls.localize('notebookActions.selectKernel', "Select Notebook Kernel"), - precondition: ContextKeyExpr.and(NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_EDITOR_FOCUSED), + precondition: NOTEBOOK_IS_ACTIVE_EDITOR, icon: { id: 'codicon/server-environment' }, menu: { id: MenuId.EditorTitle, - when: ContextKeyExpr.and(NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_HAS_MULTIPLE_KERNELS), + when: NOTEBOOK_HAS_MULTIPLE_KERNELS, group: 'navigation', order: -2, }, diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 82a056071a0..910d675b74d 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -239,7 +239,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor this._createBody(this._overlayContainer); this._generateFontInfo(); this._editorFocus = NOTEBOOK_EDITOR_FOCUSED.bindTo(this.contextKeyService); - this._editorFocus.set(true); + // this._editorFocus.set(true); this._isVisible = true; this._outputFocus = NOTEBOOK_OUTPUT_FOCUSED.bindTo(this.contextKeyService); this._editorEditable = NOTEBOOK_EDITOR_EDITABLE.bindTo(this.contextKeyService); @@ -682,7 +682,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor } if (viewState?.editorFocused) { - this._list?.focusView(); + // this._list?.focusView(); const cell = this._notebookViewModel?.viewCells[focusIdx]; if (cell) { cell.focusMode = CellFocusMode.Editor; diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts index 1ddc2846709..a29547dab75 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts @@ -57,7 +57,7 @@ export class CodeCell extends Disposable { if (model && templateData.editor) { templateData.editor.setModel(model); viewCell.attachTextEditor(templateData.editor); - if (notebookEditor.getActiveCell() === viewCell && viewCell.focusMode === CellFocusMode.Editor) { + if (notebookEditor.getActiveCell() === viewCell && viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasFocus()) { templateData.editor?.focus(); } @@ -66,7 +66,7 @@ export class CodeCell extends Disposable { this.onCellHeightChange(realContentHeight); } - if (this.notebookEditor.getActiveCell() === this.viewCell && viewCell.focusMode === CellFocusMode.Editor) { + if (this.notebookEditor.getActiveCell() === this.viewCell && viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasFocus()) { templateData.editor?.focus(); } } diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts index e106fab4e2e..f82009cd14f 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts @@ -227,7 +227,7 @@ export class StatefullMarkdownCell extends Disposable { } private focusEditorIfNeeded() { - if (this.viewCell.focusMode === CellFocusMode.Editor) { + if (this.viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasFocus()) { this.editor?.focus(); } } -- GitLab