Fix #170778. Restore cell options and editor selection on history navigation. (#174717)

This commit is contained in:
Peng Lyu
2023-02-17 12:13:38 -08:00
committed by GitHub
parent 2cab9c9c60
commit 8ca48dfd13
3 changed files with 16 additions and 5 deletions

View File

@@ -249,6 +249,7 @@ export interface ICellViewModel extends IGenericCellViewModel {
textModel: ITextModel | undefined;
hasModel(): this is IEditableCellViewModel;
resolveTextModel(): Promise<ITextModel>;
getSelections(): Selection[];
getSelectionsStartPosition(): IPosition[] | undefined;
getCellDecorations(): INotebookCellDecorationOptions[];
getCellStatusBarItems(): INotebookCellStatusBarItem[];

View File

@@ -21,6 +21,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { Selection } from 'vs/editor/common/core/selection';
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
import { DEFAULT_EDITOR_ASSOCIATION, EditorInputCapabilities, EditorPaneSelectionChangeReason, EditorPaneSelectionCompareResult, EditorResourceAccessor, IEditorMemento, IEditorOpenContext, IEditorPaneSelection, IEditorPaneSelectionChangeEvent, createEditorOpenError } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
@@ -354,9 +355,10 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane {
getSelection(): IEditorPaneSelection | undefined {
if (this._widget.value) {
const cellUri = this._widget.value.getActiveCell()?.uri;
if (cellUri) {
return new NotebookEditorSelection(cellUri);
const activeCell = this._widget.value.getActiveCell();
if (activeCell) {
const cellUri = activeCell.uri;
return new NotebookEditorSelection(cellUri, activeCell.getSelections());
}
}
@@ -421,7 +423,8 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane {
class NotebookEditorSelection implements IEditorPaneSelection {
constructor(
private readonly cellUri: URI
private readonly cellUri: URI,
private readonly selections: Selection[]
) { }
compare(other: IEditorPaneSelection): EditorPaneSelectionCompareResult {
@@ -439,7 +442,10 @@ class NotebookEditorSelection implements IEditorPaneSelection {
restore(options: IEditorOptions): INotebookEditorOptions {
const notebookOptions: INotebookEditorOptions = {
cellOptions: {
resource: this.cellUri
resource: this.cellUri,
options: {
selection: this.selections[0]
}
}
};

View File

@@ -182,6 +182,10 @@ export class NotebookProviderInfoStore extends Disposable {
cellOptions = { resource, options };
}
if (!cellOptions) {
cellOptions = (options as INotebookEditorOptions | undefined)?.cellOptions;
}
const notebookOptions = { ...options, cellOptions } as INotebookEditorOptions;
return { editor: NotebookEditorInput.create(this._instantiationService, notebookUri, notebookProviderInfo.id), options: notebookOptions };
};