@@ -35,6 +35,8 @@ import { FileService } from 'vs/platform/files/common/fileService';
35
35
import { IFileService } from 'vs/platform/files/common/files' ;
36
36
import { URI } from 'vs/base/common/uri' ;
37
37
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' ;
38
40
39
41
export const IN_NOTEBOOK_TEXT_DIFF_EDITOR = new RawContextKey < boolean > ( 'isInNotebookTextDiffEditor' , false ) ;
40
42
@@ -246,38 +248,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
246
248
}
247
249
}
248
250
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 ) ) ;
281
252
originalCellIndex = change . originalStart + change . originalLength ;
282
253
modifiedCellIndex = change . modifiedStart + change . modifiedLength ;
283
254
}
@@ -294,6 +265,43 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
294
265
this . _list . splice ( 0 , this . _list . length , cellDiffViewModels ) ;
295
266
}
296
267
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
+
297
305
private pendingLayouts = new WeakMap < CellDiffViewModel , IDisposable > ( ) ;
298
306
299
307
0 commit comments