Skip to content

Commit 8ca48df

Browse files
authored
Fix #170778. Restore cell options and editor selection on history navigation. (#174717)
1 parent 2cab9c9 commit 8ca48df

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ export interface ICellViewModel extends IGenericCellViewModel {
249249
textModel: ITextModel | undefined;
250250
hasModel(): this is IEditableCellViewModel;
251251
resolveTextModel(): Promise<ITextModel>;
252+
getSelections(): Selection[];
252253
getSelectionsStartPosition(): IPosition[] | undefined;
253254
getCellDecorations(): INotebookCellDecorationOptions[];
254255
getCellStatusBarItems(): INotebookCellStatusBarItem[];

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
2121
import { IStorageService } from 'vs/platform/storage/common/storage';
2222
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2323
import { IThemeService } from 'vs/platform/theme/common/themeService';
24+
import { Selection } from 'vs/editor/common/core/selection';
2425
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
2526
import { DEFAULT_EDITOR_ASSOCIATION, EditorInputCapabilities, EditorPaneSelectionChangeReason, EditorPaneSelectionCompareResult, EditorResourceAccessor, IEditorMemento, IEditorOpenContext, IEditorPaneSelection, IEditorPaneSelectionChangeEvent, createEditorOpenError } from 'vs/workbench/common/editor';
2627
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
@@ -354,9 +355,10 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane {
354355

355356
getSelection(): IEditorPaneSelection | undefined {
356357
if (this._widget.value) {
357-
const cellUri = this._widget.value.getActiveCell()?.uri;
358-
if (cellUri) {
359-
return new NotebookEditorSelection(cellUri);
358+
const activeCell = this._widget.value.getActiveCell();
359+
if (activeCell) {
360+
const cellUri = activeCell.uri;
361+
return new NotebookEditorSelection(cellUri, activeCell.getSelections());
360362
}
361363
}
362364

@@ -421,7 +423,8 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane {
421423
class NotebookEditorSelection implements IEditorPaneSelection {
422424

423425
constructor(
424-
private readonly cellUri: URI
426+
private readonly cellUri: URI,
427+
private readonly selections: Selection[]
425428
) { }
426429

427430
compare(other: IEditorPaneSelection): EditorPaneSelectionCompareResult {
@@ -439,7 +442,10 @@ class NotebookEditorSelection implements IEditorPaneSelection {
439442
restore(options: IEditorOptions): INotebookEditorOptions {
440443
const notebookOptions: INotebookEditorOptions = {
441444
cellOptions: {
442-
resource: this.cellUri
445+
resource: this.cellUri,
446+
options: {
447+
selection: this.selections[0]
448+
}
443449
}
444450
};
445451

src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ export class NotebookProviderInfoStore extends Disposable {
182182
cellOptions = { resource, options };
183183
}
184184

185+
if (!cellOptions) {
186+
cellOptions = (options as INotebookEditorOptions | undefined)?.cellOptions;
187+
}
188+
185189
const notebookOptions = { ...options, cellOptions } as INotebookEditorOptions;
186190
return { editor: NotebookEditorInput.create(this._instantiationService, notebookUri, notebookProviderInfo.id), options: notebookOptions };
187191
};

0 commit comments

Comments
 (0)