@@ -163,6 +163,10 @@ export class DiffFile {
163
163
164
164
fileLineLength : number = 0 ;
165
165
166
+ additionLength : number = 0 ;
167
+
168
+ deletionLength : number = 0 ;
169
+
166
170
hasExpandSplitAll : boolean = false ;
167
171
168
172
hasExpandUnifiedAll : boolean = false ;
@@ -433,6 +437,14 @@ export class DiffFile {
433
437
return this . #getOldRawLine( lineNumber ) ;
434
438
} ;
435
439
440
+ this . #diffLines = [ ] ;
441
+
442
+ this . additionLength = 0 ;
443
+
444
+ this . deletionLength = 0 ;
445
+
446
+ const tmp : DiffLine [ ] = [ ] ;
447
+
436
448
this . #diffListResults. forEach ( ( item ) => {
437
449
const hunks = item . hunks ;
438
450
hunks . forEach ( ( hunk ) => {
@@ -441,28 +453,21 @@ export class DiffFile {
441
453
hunk . lines . forEach ( ( line ) => {
442
454
if ( line . type === DiffLineType . Add ) {
443
455
additions . push ( line ) ;
456
+ this . additionLength ++ ;
444
457
} else if ( line . type === DiffLineType . Delete ) {
445
458
deletions . push ( line ) ;
459
+ this . deletionLength ++ ;
446
460
} else {
447
461
getDiffRange ( additions , deletions , { getAdditionRaw, getDeletionRaw } ) ;
448
462
additions = [ ] ;
449
463
deletions = [ ] ;
450
464
}
465
+ tmp . push ( line ) ;
451
466
} ) ;
452
467
getDiffRange ( additions , deletions , { getAdditionRaw, getDeletionRaw } ) ;
453
468
} ) ;
454
469
} ) ;
455
470
456
- this . #diffLines = [ ] ;
457
-
458
- const tmp : DiffLine [ ] = [ ] ;
459
-
460
- this . #diffListResults. forEach ( ( item ) => {
461
- item . hunks . forEach ( ( _item ) => {
462
- tmp . push ( ..._item . lines ) ;
463
- } ) ;
464
- } ) ;
465
-
466
471
let prevHunkLine : DiffHunkItem | null = null ;
467
472
468
473
this . #diffLines = tmp . map < DiffLineItem > ( ( i , index ) => {
@@ -515,21 +520,43 @@ export class DiffFile {
515
520
516
521
this . #oldFileDiffLines = { } ;
517
522
523
+ this . #newFileDiffLines = { } ;
524
+
525
+ let maxOldLineNumber = - 1 ;
526
+
527
+ let maxNewLineNumber = - 1 ;
528
+
518
529
this . #diffLines. forEach ( ( item ) => {
519
530
if ( item . oldLineNumber ) {
520
531
this . diffLineLength = Math . max ( this . diffLineLength , item . oldLineNumber ) ;
521
532
522
533
this . #oldFileDiffLines[ item . oldLineNumber ] = item ;
523
- }
524
- } ) ;
525
534
526
- this . #newFileDiffLines = { } ;
535
+ if ( __DEV__ ) {
536
+ if ( item . oldLineNumber <= maxOldLineNumber ) {
537
+ console . warn (
538
+ 'the "lineNumber" from "diff" should be in ascending order, maybe current "diff" string is not a valid "diff" string'
539
+ ) ;
540
+ }
541
+
542
+ maxOldLineNumber = Math . max ( maxOldLineNumber , item . oldLineNumber ) ;
543
+ }
544
+ }
527
545
528
- this . #diffLines. forEach ( ( item ) => {
529
546
if ( item . newLineNumber ) {
530
547
this . diffLineLength = Math . max ( this . diffLineLength , item . newLineNumber ) ;
531
548
532
549
this . #newFileDiffLines[ item . newLineNumber ] = item ;
550
+
551
+ if ( __DEV__ ) {
552
+ if ( item . newLineNumber <= maxNewLineNumber ) {
553
+ console . warn (
554
+ 'the "lineNumber" from "diff" should be in ascending order, maybe current "diff" string is not a valid "diff" string'
555
+ ) ;
556
+ }
557
+
558
+ maxNewLineNumber = Math . max ( maxNewLineNumber , item . newLineNumber ) ;
559
+ }
533
560
}
534
561
} ) ;
535
562
}
@@ -635,7 +662,7 @@ export class DiffFile {
635
662
const maxOldFileLineNumber = this . #oldFileResult?. maxLineNumber || 0 ;
636
663
const maxNewFileLineNumber = this . #newFileResult?. maxLineNumber || 0 ;
637
664
638
- if ( __DEV__ && ! this . #oldFileResult && ! this . #newFileResult) {
665
+ if ( __DEV__ && ! this . #oldFileResult && ! this . #newFileResult && this . #composeByMerge ) {
639
666
console . error (
640
667
"this instance can not `buildSplitDiffLines` because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'"
641
668
) ;
@@ -821,7 +848,7 @@ export class DiffFile {
821
848
const maxOldFileLineNumber = this . #oldFileResult?. maxLineNumber || 0 ;
822
849
const maxNewFileLineNumber = this . #newFileResult?. maxLineNumber || 0 ;
823
850
824
- if ( __DEV__ && ! this . #oldFileResult && ! this . #newFileResult) {
851
+ if ( __DEV__ && ! this . #oldFileResult && ! this . #newFileResult && this . #composeByMerge ) {
825
852
console . error (
826
853
"this instance can not `buildUnifiedDiffLines` because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'"
827
854
) ;
@@ -1081,11 +1108,13 @@ export class DiffFile {
1081
1108
return this . #unifiedHunksLines?. [ index ] ;
1082
1109
} ;
1083
1110
1111
+ // TODO! support rollback?
1084
1112
onUnifiedHunkExpand = ( dir : "up" | "down" | "all" , index : number , needTrigger = true ) => {
1113
+ if ( this . #composeByDiff) return ;
1114
+
1085
1115
const current = this . #unifiedHunksLines?. [ index ] ;
1086
- if ( ! current || ! current . unifiedInfo ) return ;
1087
1116
1088
- if ( this . #composeByDiff ) return ;
1117
+ if ( ! current || ! current . unifiedInfo ) return ;
1089
1118
1090
1119
if ( dir === "all" ) {
1091
1120
for ( let i = current . unifiedInfo . startHiddenIndex ; i < current . unifiedInfo . endHiddenIndex ; i ++ ) {
@@ -1290,6 +1319,8 @@ export class DiffFile {
1290
1319
const splitLineLength = this . splitLineLength ;
1291
1320
const unifiedLineLength = this . unifiedLineLength ;
1292
1321
const fileLineLength = this . fileLineLength ;
1322
+ const additionLength = this . additionLength ;
1323
+ const deletionLength = this . deletionLength ;
1293
1324
const composeByDiff = this . #composeByDiff;
1294
1325
const highlighterName = this . #highlighterName;
1295
1326
const highlighterType = this . #highlighterType;
@@ -1323,6 +1354,8 @@ export class DiffFile {
1323
1354
splitLineLength,
1324
1355
unifiedLineLength,
1325
1356
fileLineLength,
1357
+ additionLength,
1358
+ deletionLength,
1326
1359
splitLeftLines,
1327
1360
splitRightLines,
1328
1361
splitHunkLines,
@@ -1362,6 +1395,8 @@ export class DiffFile {
1362
1395
this . splitLineLength = data . splitLineLength ;
1363
1396
this . unifiedLineLength = data . unifiedLineLength ;
1364
1397
this . fileLineLength = data . fileLineLength ;
1398
+ this . additionLength = data . additionLength ;
1399
+ this . deletionLength = data . deletionLength ;
1365
1400
this . hasSomeLineCollapsed = data . hasSomeLineCollapsed ;
1366
1401
1367
1402
this . #splitLeftLines = data . splitLeftLines ;
0 commit comments