notebook document data loss.

This commit is contained in:
rebornix 2020-09-11 10:57:39 -07:00
parent 07ad5d6f18
commit 59dcc5c912
4 changed files with 44 additions and 35 deletions

View file

@ -271,7 +271,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
const notebookDocumentAddedHandler = (textModel: NotebookTextModel) => {
if (!this._editorEventListenersMapping.has(textModel.uri.toString())) {
if (!this._documentEventListenersMapping.has(textModel.uri)) {
const disposableStore = new DisposableStore();
disposableStore.add(textModel!.onDidChangeContent(event => {
const dto = event.rawEvents.map(e => {
@ -316,7 +316,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
this._proxy.$acceptDocumentPropertiesChanged(textModel.uri, { metadata: textModel.metadata });
}
}));
this._editorEventListenersMapping.set(textModel!.uri.toString(), disposableStore);
this._documentEventListenersMapping.set(textModel!.uri, disposableStore);
}
};

View file

@ -348,6 +348,7 @@ export class ExtHostNotebookDocument extends Disposable {
}
acceptModelChanged(event: NotebookCellsChangedEventDto, isDirty: boolean): void {
console.log(event);
this._versionId = event.versionId;
this._isDirty = isDirty;
event.rawEvents.forEach(e => {

View file

@ -35,6 +35,8 @@ import { FileService } from 'vs/platform/files/common/fileService';
import { IFileService } from 'vs/platform/files/common/files';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import { IDiffChange } from 'vs/base/common/diff/diff';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
export const IN_NOTEBOOK_TEXT_DIFF_EDITOR = new RawContextKey<boolean>('isInNotebookTextDiffEditor', false);
@ -246,38 +248,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
}
}
// modified cells
const modifiedLen = Math.min(change.originalLength, change.modifiedLength);
for (let j = 0; j < modifiedLen; j++) {
cellDiffViewModels.push(new CellDiffViewModel(
originalModel.cells[change.originalStart + j],
modifiedModel.cells[change.modifiedStart + j],
'modified',
this._eventDispatcher!
));
}
for (let j = modifiedLen; j < change.originalLength; j++) {
// deletion
cellDiffViewModels.push(new CellDiffViewModel(
originalModel.cells[change.originalStart + j],
undefined,
'delete',
this._eventDispatcher!
));
}
for (let j = modifiedLen; j < change.modifiedLength; j++) {
// insertion
cellDiffViewModels.push(new CellDiffViewModel(
undefined,
modifiedModel.cells[change.modifiedStart + j],
'insert',
this._eventDispatcher!
));
}
cellDiffViewModels.push(...this._computeModifiedLCS(change, originalModel, modifiedModel));
originalCellIndex = change.originalStart + change.originalLength;
modifiedCellIndex = change.modifiedStart + change.modifiedLength;
}
@ -294,6 +265,43 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
this._list.splice(0, this._list.length, cellDiffViewModels);
}
private _computeModifiedLCS(change: IDiffChange, originalModel: NotebookTextModel, modifiedModel: NotebookTextModel) {
const result: CellDiffViewModel[] = [];
// modified cells
const modifiedLen = Math.min(change.originalLength, change.modifiedLength);
for (let j = 0; j < modifiedLen; j++) {
result.push(new CellDiffViewModel(
originalModel.cells[change.originalStart + j],
modifiedModel.cells[change.modifiedStart + j],
'modified',
this._eventDispatcher!
));
}
for (let j = modifiedLen; j < change.originalLength; j++) {
// deletion
result.push(new CellDiffViewModel(
originalModel.cells[change.originalStart + j],
undefined,
'delete',
this._eventDispatcher!
));
}
for (let j = modifiedLen; j < change.modifiedLength; j++) {
// insertion
result.push(new CellDiffViewModel(
undefined,
modifiedModel.cells[change.modifiedStart + j],
'insert',
this._eventDispatcher!
));
}
return result;
}
private pendingLayouts = new WeakMap<CellDiffViewModel, IDisposable>();

View file

@ -109,7 +109,7 @@ export class NotebookCellTextModel extends Disposable implements ICell {
}
// TODO@rebornix, raw outputs
this._hash = hash([hash(this.getValue()), this._getPersisentMetadata, this.transientOptions.transientOutputs ? [] : this._outputs]);
this._hash = hash([hash(this.language), hash(this.getValue()), this._getPersisentMetadata, this.transientOptions.transientOutputs ? [] : this._outputs]);
return this._hash;
}