Skip to content

Commit 59dcc5c

Browse files
committed
notebook document data loss.
1 parent 07ad5d6 commit 59dcc5c

File tree

4 files changed

+44
-35
lines changed

4 files changed

+44
-35
lines changed

src/vs/workbench/api/browser/mainThreadNotebook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
271271

272272

273273
const notebookDocumentAddedHandler = (textModel: NotebookTextModel) => {
274-
if (!this._editorEventListenersMapping.has(textModel.uri.toString())) {
274+
if (!this._documentEventListenersMapping.has(textModel.uri)) {
275275
const disposableStore = new DisposableStore();
276276
disposableStore.add(textModel!.onDidChangeContent(event => {
277277
const dto = event.rawEvents.map(e => {
@@ -316,7 +316,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
316316
this._proxy.$acceptDocumentPropertiesChanged(textModel.uri, { metadata: textModel.metadata });
317317
}
318318
}));
319-
this._editorEventListenersMapping.set(textModel!.uri.toString(), disposableStore);
319+
this._documentEventListenersMapping.set(textModel!.uri, disposableStore);
320320
}
321321
};
322322

src/vs/workbench/api/common/extHostNotebookDocument.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ export class ExtHostNotebookDocument extends Disposable {
348348
}
349349

350350
acceptModelChanged(event: NotebookCellsChangedEventDto, isDirty: boolean): void {
351+
console.log(event);
351352
this._versionId = event.versionId;
352353
this._isDirty = isDirty;
353354
event.rawEvents.forEach(e => {

src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import { FileService } from 'vs/platform/files/common/fileService';
3535
import { IFileService } from 'vs/platform/files/common/files';
3636
import { URI } from 'vs/base/common/uri';
3737
import { Schemas } from 'vs/base/common/network';
38+
import { IDiffChange } from 'vs/base/common/diff/diff';
39+
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
3840

3941
export const IN_NOTEBOOK_TEXT_DIFF_EDITOR = new RawContextKey<boolean>('isInNotebookTextDiffEditor', false);
4042

@@ -246,38 +248,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
246248
}
247249
}
248250

249-
// modified cells
250-
const modifiedLen = Math.min(change.originalLength, change.modifiedLength);
251-
252-
for (let j = 0; j < modifiedLen; j++) {
253-
cellDiffViewModels.push(new CellDiffViewModel(
254-
originalModel.cells[change.originalStart + j],
255-
modifiedModel.cells[change.modifiedStart + j],
256-
'modified',
257-
this._eventDispatcher!
258-
));
259-
}
260-
261-
for (let j = modifiedLen; j < change.originalLength; j++) {
262-
// deletion
263-
cellDiffViewModels.push(new CellDiffViewModel(
264-
originalModel.cells[change.originalStart + j],
265-
undefined,
266-
'delete',
267-
this._eventDispatcher!
268-
));
269-
}
270-
271-
for (let j = modifiedLen; j < change.modifiedLength; j++) {
272-
// insertion
273-
cellDiffViewModels.push(new CellDiffViewModel(
274-
undefined,
275-
modifiedModel.cells[change.modifiedStart + j],
276-
'insert',
277-
this._eventDispatcher!
278-
));
279-
}
280-
251+
cellDiffViewModels.push(...this._computeModifiedLCS(change, originalModel, modifiedModel));
281252
originalCellIndex = change.originalStart + change.originalLength;
282253
modifiedCellIndex = change.modifiedStart + change.modifiedLength;
283254
}
@@ -294,6 +265,43 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
294265
this._list.splice(0, this._list.length, cellDiffViewModels);
295266
}
296267

268+
private _computeModifiedLCS(change: IDiffChange, originalModel: NotebookTextModel, modifiedModel: NotebookTextModel) {
269+
const result: CellDiffViewModel[] = [];
270+
// modified cells
271+
const modifiedLen = Math.min(change.originalLength, change.modifiedLength);
272+
273+
for (let j = 0; j < modifiedLen; j++) {
274+
result.push(new CellDiffViewModel(
275+
originalModel.cells[change.originalStart + j],
276+
modifiedModel.cells[change.modifiedStart + j],
277+
'modified',
278+
this._eventDispatcher!
279+
));
280+
}
281+
282+
for (let j = modifiedLen; j < change.originalLength; j++) {
283+
// deletion
284+
result.push(new CellDiffViewModel(
285+
originalModel.cells[change.originalStart + j],
286+
undefined,
287+
'delete',
288+
this._eventDispatcher!
289+
));
290+
}
291+
292+
for (let j = modifiedLen; j < change.modifiedLength; j++) {
293+
// insertion
294+
result.push(new CellDiffViewModel(
295+
undefined,
296+
modifiedModel.cells[change.modifiedStart + j],
297+
'insert',
298+
this._eventDispatcher!
299+
));
300+
}
301+
302+
return result;
303+
}
304+
297305
private pendingLayouts = new WeakMap<CellDiffViewModel, IDisposable>();
298306

299307

src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class NotebookCellTextModel extends Disposable implements ICell {
109109
}
110110

111111
// TODO@rebornix, raw outputs
112-
this._hash = hash([hash(this.getValue()), this._getPersisentMetadata, this.transientOptions.transientOutputs ? [] : this._outputs]);
112+
this._hash = hash([hash(this.language), hash(this.getValue()), this._getPersisentMetadata, this.transientOptions.transientOutputs ? [] : this._outputs]);
113113
return this._hash;
114114
}
115115

0 commit comments

Comments
 (0)