Skip to content

Commit fcfb0dd

Browse files
committed
notebookCellListFocus
1 parent 79fa27d commit fcfb0dd

5 files changed

Lines changed: 32 additions & 11 deletions

File tree

extensions/vscode-notebook-tests/src/notebook.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,8 @@ suite('metadata', () => {
804804
});
805805

806806

807-
test('custom metadata should be supported', async function () {
807+
// TODO@rebornix skip as it crashes the process all the time
808+
test.skip('custom metadata should be supported', async function () {
808809
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
809810
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
810811
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');

src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { InputFocusedContext, InputFocusedContextKey } from 'vs/platform/context
1818
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1919
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
2020
import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
21-
import { BaseCellRenderTemplate, CellEditState, ICellViewModel, INotebookEditor, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_CELL_HAS_OUTPUTS, CellFocusMode, NOTEBOOK_OUTPUT_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
21+
import { BaseCellRenderTemplate, CellEditState, ICellViewModel, INotebookEditor, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_CELL_HAS_OUTPUTS, CellFocusMode, NOTEBOOK_OUTPUT_FOCUSED, NOTEBOOK_CELL_LIST_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
2222
import { CellKind, NOTEBOOK_EDITOR_CURSOR_BOUNDARY, NotebookCellRunState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
2323
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
2424
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
@@ -154,7 +154,7 @@ registerAction2(class extends NotebookAction {
154154
id: EXECUTE_CELL_COMMAND_ID,
155155
title: localize('notebookActions.execute', "Execute Cell"),
156156
keybinding: {
157-
when: NOTEBOOK_EDITOR_FOCUSED,
157+
when: NOTEBOOK_CELL_LIST_FOCUSED,
158158
primary: KeyMod.WinCtrl | KeyCode.Enter,
159159
win: {
160160
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Enter
@@ -227,7 +227,7 @@ registerAction2(class extends NotebookAction {
227227
id: EXECUTE_CELL_SELECT_BELOW,
228228
title: localize('notebookActions.executeAndSelectBelow', "Execute Notebook Cell and Select Below"),
229229
keybinding: {
230-
when: NOTEBOOK_EDITOR_FOCUSED,
230+
when: NOTEBOOK_CELL_LIST_FOCUSED,
231231
primary: KeyMod.Shift | KeyCode.Enter,
232232
weight: EDITOR_WIDGET_ACTION_WEIGHT
233233
},
@@ -263,7 +263,7 @@ registerAction2(class extends NotebookAction {
263263
id: EXECUTE_CELL_INSERT_BELOW,
264264
title: localize('notebookActions.executeAndInsertBelow', "Execute Notebook Cell and Insert Below"),
265265
keybinding: {
266-
when: NOTEBOOK_EDITOR_FOCUSED,
266+
when: NOTEBOOK_CELL_LIST_FOCUSED,
267267
primary: KeyMod.Alt | KeyCode.Enter,
268268
weight: EDITOR_WIDGET_ACTION_WEIGHT
269269
},
@@ -487,7 +487,7 @@ registerAction2(class extends InsertCellCommand {
487487
title: localize('notebookActions.insertCodeCellAbove', "Insert Code Cell Above"),
488488
keybinding: {
489489
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.Enter,
490-
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, InputFocusedContext.toNegated()),
490+
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, InputFocusedContext.toNegated()),
491491
weight: KeybindingWeight.WorkbenchContrib
492492
},
493493
},
@@ -504,7 +504,7 @@ registerAction2(class extends InsertCellCommand {
504504
title: localize('notebookActions.insertCodeCellBelow', "Insert Code Cell Below"),
505505
keybinding: {
506506
primary: KeyMod.CtrlCmd | KeyCode.Enter,
507-
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, InputFocusedContext.toNegated()),
507+
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, InputFocusedContext.toNegated()),
508508
weight: KeybindingWeight.WorkbenchContrib
509509
},
510510
},
@@ -564,7 +564,7 @@ registerAction2(class extends NotebookAction {
564564
id: EDIT_CELL_COMMAND_ID,
565565
title: localize('notebookActions.editCell', "Edit Cell"),
566566
keybinding: {
567-
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)),
567+
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)),
568568
primary: KeyCode.Enter,
569569
weight: KeybindingWeight.WorkbenchContrib
570570
},

src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const NOTEBOOK_IS_ACTIVE_EDITOR = ContextKeyExpr.equals('activeEditor', '
3434

3535
// Editor keys
3636
export const NOTEBOOK_EDITOR_FOCUSED = new RawContextKey<boolean>('notebookEditorFocused', false);
37+
export const NOTEBOOK_CELL_LIST_FOCUSED = new RawContextKey<boolean>('notebookCellListFocused', false);
3738
export const NOTEBOOK_OUTPUT_FOCUSED = new RawContextKey<boolean>('notebookOutputFocused', false);
3839
export const NOTEBOOK_EDITOR_EDITABLE = new RawContextKey<boolean>('notebookEditable', true);
3940
export const NOTEBOOK_EDITOR_RUNNABLE = new RawContextKey<boolean>('notebookRunnable', true);

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { registerThemingParticipant } from 'vs/platform/theme/common/themeServic
2828
import { EditorMemento } from 'vs/workbench/browser/parts/editor/baseEditor';
2929
import { EditorOptions, IEditorMemento } from 'vs/workbench/common/editor';
3030
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';
31-
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';
31+
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';
3232
import { NotebookEditorExtensionsRegistry } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
3333
import { NotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookCellList';
3434
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/output/outputRenderer';
@@ -83,7 +83,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
8383
private _fontInfo: BareFontInfo | undefined;
8484
private _dimension: DOM.Dimension | null = null;
8585
private _shadowElementViewInfo: { height: number, width: number, top: number; left: number; } | null = null;
86+
87+
private _cellListFocusTracker: DOM.IFocusTracker;
8688
private _editorFocus: IContextKey<boolean> | null = null;
89+
private _cellListFocus: IContextKey<boolean> | null = null;
8790
private _outputFocus: IContextKey<boolean> | null = null;
8891
private _editorEditable: IContextKey<boolean> | null = null;
8992
private _editorRunnable: IContextKey<boolean> | null = null;
@@ -219,6 +222,12 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
219222
// Note - focus going to the webview will fire 'blur', but the webview element will be
220223
// a descendent of the notebook editor root.
221224
const focused = DOM.isAncestor(document.activeElement, this._overlayContainer);
225+
if (focused) {
226+
const cellListFocused = DOM.isAncestor(document.activeElement, this._body);
227+
this._cellListFocus?.set(cellListFocused);
228+
} else {
229+
this._cellListFocus?.set(false);
230+
}
222231
this._editorFocus?.set(focused);
223232
this._notebookViewModel?.setFocus(focused);
224233
}
@@ -239,6 +248,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
239248
this._createBody(this._overlayContainer);
240249
this._generateFontInfo();
241250
this._editorFocus = NOTEBOOK_EDITOR_FOCUSED.bindTo(this.contextKeyService);
251+
this._cellListFocus = NOTEBOOK_CELL_LIST_FOCUSED.bindTo(this.contextKeyService);
242252
this._isVisible = true;
243253
this._outputFocus = NOTEBOOK_OUTPUT_FOCUSED.bindTo(this.contextKeyService);
244254
this._editorEditable = NOTEBOOK_EDITOR_EDITABLE.bindTo(this.contextKeyService);
@@ -368,6 +378,14 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
368378
const widgetFocusTracker = DOM.trackFocus(this.getDomNode());
369379
this._register(widgetFocusTracker);
370380
this._register(widgetFocusTracker.onDidFocus(() => this._onDidFocusEmitter.fire()));
381+
382+
this._cellListFocusTracker = this._register(DOM.trackFocus(this._body));
383+
this._register(this._cellListFocusTracker.onDidFocus(() => {
384+
this.updateEditorFocus();
385+
}));
386+
this._register(this._cellListFocusTracker.onDidBlur(() => {
387+
this.updateEditorFocus();
388+
}));
371389
}
372390

373391
getDomNode() {

src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ export abstract class BaseCellViewModel extends Disposable {
9494
}>();
9595
private _lastDecorationId: number = 0;
9696

97+
private _textModel: model.ITextModel | undefined = undefined;
9798
get textModel(): model.ITextModel | undefined {
98-
return this.model.textModel;
99+
return this._textModel;
99100
}
100101

101102
set textModel(m: model.ITextModel | undefined) {
102-
this.model.textModel = m;
103+
this._textModel = m;
103104
}
104105

105106
hasModel(): this is IEditableCellViewModel {

0 commit comments

Comments
 (0)