diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index da081a84cfb..0733150cb6b 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -350,6 +350,7 @@ export interface INotebookEditorViewState { editingCells: { [key: number]: boolean }; collapsedInputCells: { [key: number]: boolean }; collapsedOutputCells: { [key: number]: boolean }; + cellLineNumberStates: { [key: number]: 'on' | 'off' }; editorViewStates: { [key: number]: editorCommon.ICodeEditorViewState | null }; hiddenFoldingRanges?: ICellRange[]; cellTotalHeights?: { [key: number]: number }; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index c91c6e6aef6..e94e73ce104 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -1650,6 +1650,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD if (!state) { return { editingCells: {}, + cellLineNumberStates: {}, editorViewStates: {}, collapsedInputCells: {}, collapsedOutputCells: {}, @@ -1661,11 +1662,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD const cellHeights: { [key: number]: number } = {}; for (let i = 0; i < this.viewModel!.length; i++) { const elm = this.viewModel!.cellAt(i) as CellViewModel; - if (elm.cellKind === CellKind.Code) { - cellHeights[i] = elm.layoutInfo.totalHeight; - } else { - cellHeights[i] = elm.layoutInfo.totalHeight; - } + cellHeights[i] = elm.layoutInfo.totalHeight; } state.cellTotalHeights = cellHeights; diff --git a/src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.ts b/src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.ts index f80243d2591..fbf438f5162 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.ts @@ -131,9 +131,9 @@ export class CodeCell extends Disposable { this._register(Event.runAndSubscribe(viewCell.onDidChangeOutputs, this.updateForOutputs.bind(this))); this._register(Event.runAndSubscribe(viewCell.onDidChangeLayout, this.updateForLayout.bind(this))); + cellEditorOptions.setLineNumbers(this.viewCell.lineNumbers); this._register(cellEditorOptions.onDidChange(() => templateData.editor.updateOptions(cellEditorOptions.getUpdatedValue(this.viewCell.internalMetadata, this.viewCell.uri)))); templateData.editor.updateOptions(cellEditorOptions.getUpdatedValue(this.viewCell.internalMetadata, this.viewCell.uri)); - cellEditorOptions.setLineNumbers(this.viewCell.lineNumbers); } private _pendingLayout: IDisposable | undefined; diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.ts index 4337c50d40b..9308ddf9cf0 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.ts @@ -765,6 +765,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD const editingCells: { [key: number]: boolean } = {}; const collapsedInputCells: { [key: number]: boolean } = {}; const collapsedOutputCells: { [key: number]: boolean } = {}; + const cellLineNumberStates: { [key: number]: 'on' | 'off' } = {}; this._viewCells.forEach((cell, i) => { if (cell.getEditState() === CellEditState.Editing) { @@ -778,6 +779,10 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD if (cell instanceof CodeCellViewModel && cell.isOutputCollapsed) { collapsedOutputCells[i] = true; } + + if (cell.lineNumbers !== 'inherit') { + cellLineNumberStates[i] = cell.lineNumbers; + } }); const editorViewStates: { [key: number]: editorCommon.ICodeEditorViewState } = {}; this._viewCells.map(cell => ({ handle: cell.model.handle, state: cell.saveEditorViewState() })).forEach((viewState, i) => { @@ -789,6 +794,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD return { editingCells, editorViewStates, + cellLineNumberStates, collapsedInputCells, collapsedOutputCells }; @@ -812,6 +818,9 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD if (viewState.collapsedOutputCells && viewState.collapsedOutputCells[index] && cell instanceof CodeCellViewModel) { cell.isOutputCollapsed = true; } + if (viewState.cellLineNumberStates && viewState.cellLineNumberStates[index]) { + cell.lineNumbers = viewState.cellLineNumberStates[index]; + } }); } diff --git a/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts b/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts index f3e849fe8a6..5fd27dee8c2 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts @@ -40,6 +40,7 @@ suite('NotebookCellList', () => { async (editor, viewModel) => { viewModel.restoreEditorViewState({ editingCells: [false, false, false, false, false], + cellLineNumberStates: {}, editorViewStates: [null, null, null, null, null], cellTotalHeights: [50, 100, 50, 100, 50], collapsedInputCells: {}, @@ -88,6 +89,7 @@ suite('NotebookCellList', () => { editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], cellTotalHeights: [50, 100, 50, 100, 50], + cellLineNumberStates: {}, collapsedInputCells: {}, collapsedOutputCells: {}, }); @@ -131,6 +133,7 @@ suite('NotebookCellList', () => { editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], cellTotalHeights: [50, 100, 50, 100, 50], + cellLineNumberStates: {}, collapsedInputCells: {}, collapsedOutputCells: {}, }); @@ -167,6 +170,7 @@ suite('NotebookCellList', () => { editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], cellTotalHeights: [50, 100, 50, 100, 50], + cellLineNumberStates: {}, collapsedInputCells: {}, collapsedOutputCells: {}, }); @@ -208,6 +212,7 @@ suite('NotebookCellList', () => { editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], cellTotalHeights: [50, 100, 50, 100, 50], + cellLineNumberStates: {}, collapsedInputCells: {}, collapsedOutputCells: {}, }); @@ -260,6 +265,7 @@ suite('NotebookCellList', () => { editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], cellTotalHeights: [50, 100, 50, 100, 50], + cellLineNumberStates: {}, collapsedInputCells: {}, collapsedOutputCells: {}, }); @@ -295,6 +301,7 @@ suite('NotebookCellList', () => { editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], cellTotalHeights: [50, 100, 50, 100, 50], + cellLineNumberStates: {}, collapsedInputCells: {}, collapsedOutputCells: {}, }); @@ -343,6 +350,7 @@ suite('NotebookCellList', () => { editingCells: [false], editorViewStates: [null], cellTotalHeights: [50], + cellLineNumberStates: {}, collapsedInputCells: {}, collapsedOutputCells: {}, });