private outputs slice and unknown change.

This commit is contained in:
rebornix 2020-09-10 10:33:49 -07:00
parent f0426274b4
commit 2103630537
6 changed files with 61 additions and 25 deletions

View file

@ -494,11 +494,6 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
return;
}
async $onNotebookChange(_viewType: string, uri: UriComponents): Promise<void> {
const textModel = this._notebookService.getNotebookTextModel(URI.from(uri));
textModel?.handleUnknownChange();
}
async $unregisterNotebookProvider(viewType: string): Promise<void> {
const entry = this._notebookProviders.get(viewType);
if (entry) {
@ -571,10 +566,24 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
this.logService.debug('MainThreadNotebooks#spliceNotebookCellOutputs', resource.path, cellHandle);
const textModel = this._notebookService.getNotebookTextModel(URI.from(resource));
if (textModel) {
this._notebookService.transformSpliceOutputs(textModel, splices);
textModel._spliceNotebookCellOutputs(cellHandle, splices);
if (!textModel) {
return;
}
this._notebookService.transformSpliceOutputs(textModel, splices);
const cell = textModel.cells.find(cell => cell.handle === cellHandle);
if (!cell) {
return;
}
textModel.applyEdit(textModel.versionId, [
{
editType: CellEditType.OutputsSplice,
index: textModel.cells.indexOf(cell),
splices
}
], true);
}
async $postMessage(editorId: string, forRendererId: string | undefined, value: any): Promise<boolean> {
@ -587,11 +596,11 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
return false;
}
$onDidEdit(resource: UriComponents, viewType: string, editId: number, label: string | undefined): void {
$onUndoableContentChange(resource: UriComponents, viewType: string, editId: number, label: string | undefined): void {
const textModel = this._notebookService.getNotebookTextModel(URI.from(resource));
if (textModel) {
textModel.handleUnknownEdit(label, () => {
textModel.handleUnknownUndoableEdit(label, () => {
const isDirty = this._workingCopyService.isDirty(textModel.uri.with({ scheme: Schemas.vscodeNotebook }));
return this._proxy.$undoNotebook(textModel.viewType, textModel.uri, editId, isDirty);
}, () => {
@ -603,7 +612,14 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
$onContentChange(resource: UriComponents, viewType: string): void {
const textModel = this._notebookService.getNotebookTextModel(URI.from(resource));
textModel?.handleUnknownChange();
if (textModel) {
textModel.applyEdit(textModel.versionId, [
{
editType: CellEditType.Unknown
}
], true);
}
}
async $tryRevealRange(id: string, range: ICellRange, revealType: NotebookEditorRevealType) {

View file

@ -736,7 +736,6 @@ export type INotebookCellStatusBarEntryDto = Dto<INotebookCellStatusBarEntry>;
export interface MainThreadNotebookShape extends IDisposable {
$registerNotebookProvider(extension: NotebookExtensionDescription, viewType: string, supportBackup: boolean, options: { transientOutputs: boolean; transientMetadata: TransientMetadata }): Promise<void>;
$onNotebookChange(viewType: string, resource: UriComponents): Promise<void>;
$unregisterNotebookProvider(viewType: string): Promise<void>;
$registerNotebookKernelProvider(extension: NotebookExtensionDescription, handle: number, documentFilter: INotebookDocumentFilter): Promise<void>;
$unregisterNotebookKernelProvider(handle: number): Promise<void>;
@ -747,7 +746,7 @@ export interface MainThreadNotebookShape extends IDisposable {
$postMessage(editorId: string, forRendererId: string | undefined, value: any): Promise<boolean>;
$setStatusBarEntry(id: number, statusBarEntry: INotebookCellStatusBarEntryDto): Promise<void>;
$tryRevealRange(id: string, range: ICellRange, revealType: NotebookEditorRevealType): Promise<void>;
$onDidEdit(resource: UriComponents, viewType: string, editId: number, label: string | undefined): void;
$onUndoableContentChange(resource: UriComponents, viewType: string, editId: number, label: string | undefined): void;
$onContentChange(resource: UriComponents, viewType: string): void;
}

View file

@ -304,7 +304,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
if (isEditEvent(e)) {
const editId = document.addEdit(e);
this._proxy.$onDidEdit(e.document.uri, viewType, editId, e.label);
this._proxy.$onUndoableContentChange(e.document.uri, viewType, editId, e.label);
} else {
this._proxy.$onContentChange(e.document.uri, viewType);
}

View file

@ -225,7 +225,7 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook
if (prev.editType === CellEditType.Replace && editData.cellEdits[i].editType === CellEditType.Replace) {
const edit = editData.cellEdits[i];
if (edit.editType !== CellEditType.DocumentMetadata && prev.index === edit.index) {
if ((edit.editType !== CellEditType.DocumentMetadata && edit.editType !== CellEditType.Unknown) && prev.index === edit.index) {
prev.cells.push(...(editData.cellEdits[i] as ICellReplaceEdit).cells);
prev.count += (editData.cellEdits[i] as ICellReplaceEdit).count;
continue;

View file

@ -303,7 +303,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
return {
edit,
end:
edit.editType === CellEditType.DocumentMetadata
(edit.editType === CellEditType.DocumentMetadata || edit.editType === CellEditType.Unknown)
? undefined
: (edit.editType === CellEditType.Replace ? edit.index + edit.count : edit.index),
originalIndex: index,
@ -332,6 +332,14 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
// TODO@rebornix, we should do diff first
this._spliceNotebookCellOutputs(cell.handle, [[0, cell.outputs.length, edit.outputs]]);
break;
case CellEditType.OutputsSplice:
{
//TODO@joh,@rebornix no event, no undo stop (?)
this._assertIndex(edit.index);
const cell = this._cells[edit.index];
this._spliceNotebookCellOutputs(cell.handle, edit.splices);
break;
}
case CellEditType.Metadata:
this._assertIndex(edit.index);
this._changeCellMetadata(this._cells[edit.index].handle, edit.metadata, true);
@ -343,6 +351,9 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
case CellEditType.DocumentMetadata:
this._updateNotebookMetadata(edit.metadata);
break;
case CellEditType.Unknown:
this._handleUnknownChange();
break;
}
}
@ -351,8 +362,11 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
return true;
}
createSnapshot(preserveBOM?: boolean): ITextSnapshot {
return new NotebookTextModelSnapshot(this);
}
handleUnknownEdit(label: string | undefined, undo: () => void, redo: () => void): void {
handleUnknownUndoableEdit(label: string | undefined, undo: () => void, redo: () => void): void {
this._operationManager.pushEditOperation({
type: UndoRedoElementType.Resource,
resource: this.uri,
@ -371,17 +385,13 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
}, true);
}
handleUnknownChange() {
private _handleUnknownChange() {
this._eventEmitter.emit({
kind: NotebookCellsChangeType.Unknown,
transient: false
}, true);
}
createSnapshot(preserveBOM?: boolean): ITextSnapshot {
return new NotebookTextModelSnapshot(this);
}
private _replaceCells(index: number, count: number, cellDtos: ICellDto2[], synchronous: boolean): void {
if (count === 0 && cellDtos.length === 0) {
@ -552,8 +562,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
}
}
// TODO@rebornix, once adopted the new Edit API in ext host, the method should be private.
_spliceNotebookCellOutputs(cellHandle: number, splices: NotebookCellOutputsSplice[]): void {
private _spliceNotebookCellOutputs(cellHandle: number, splices: NotebookCellOutputsSplice[]): void {
const cell = this._mapping.get(cellHandle);
if (cell) {
cell.spliceNotebookCellOutputs(splices);

View file

@ -422,6 +422,8 @@ export const enum CellEditType {
Metadata = 3,
CellLanguage = 4,
DocumentMetadata = 5,
OutputsSplice = 6,
Unknown = 7
}
export interface ICellDto2 {
@ -463,7 +465,17 @@ export interface IDocumentMetadataEdit {
metadata: NotebookDocumentMetadata;
}
export type ICellEditOperation = ICellReplaceEdit | ICellOutputEdit | ICellMetadataEdit | ICellLanguageEdit | IDocumentMetadataEdit;
export interface ICellOutputsSplice {
editType: CellEditType.OutputsSplice;
index: number;
splices: NotebookCellOutputsSplice[];
}
export interface IDocumentUnknownEdit {
editType: CellEditType.Unknown;
}
export type ICellEditOperation = ICellReplaceEdit | ICellOutputEdit | ICellMetadataEdit | ICellLanguageEdit | IDocumentMetadataEdit | ICellOutputsSplice | IDocumentUnknownEdit;
export interface INotebookEditData {
documentVersionId: number;