提交 9504dda6 编写于 作者: R Rob Lourens

Don't steal focus when restoring notebook editor state

Fix #101622
上级 46c2494c
......@@ -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,
},
......
......@@ -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;
......
......@@ -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();
}
}
......
......@@ -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();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册