3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- import { diffChars } from 'diff'
6
+ import { diffWordsWithSpace } from 'diff'
7
7
import * as vscode from 'vscode'
8
8
import { ToolkitError , getLogger } from 'aws-core-vscode/shared'
9
9
import { diffUtilities } from 'aws-core-vscode/shared'
@@ -413,45 +413,6 @@ export class SvgGenerationService {
413
413
const originalRanges : Range [ ] = [ ]
414
414
const afterRanges : Range [ ] = [ ]
415
415
416
- /**
417
- * Merges ranges on the same line that are separated by only one character
418
- */
419
- const mergeAdjacentRanges = ( ranges : Range [ ] ) : Range [ ] => {
420
- const sortedRanges = [ ...ranges ] . sort ( ( a , b ) => {
421
- if ( a . line !== b . line ) {
422
- return a . line - b . line
423
- }
424
- return a . start - b . start
425
- } )
426
-
427
- const result : Range [ ] = [ ]
428
-
429
- // Process all ranges
430
- for ( let i = 0 ; i < sortedRanges . length ; i ++ ) {
431
- const current = sortedRanges [ i ]
432
-
433
- // If this is the last range or ranges are on different lines, add it directly
434
- if ( i === sortedRanges . length - 1 || current . line !== sortedRanges [ i + 1 ] . line ) {
435
- result . push ( current )
436
- continue
437
- }
438
-
439
- // Check if current range and next range can be merged
440
- const next = sortedRanges [ i + 1 ]
441
- if ( current . line === next . line && next . start - current . end <= 1 ) {
442
- sortedRanges [ i + 1 ] = {
443
- line : current . line ,
444
- start : current . start ,
445
- end : Math . max ( current . end , next . end ) ,
446
- }
447
- } else {
448
- result . push ( current )
449
- }
450
- }
451
-
452
- return result
453
- }
454
-
455
416
// Create reverse mapping for quicker lookups
456
417
const reverseMap = new Map < string , string > ( )
457
418
for ( const [ original , modified ] of modifiedLines . entries ( ) ) {
@@ -465,7 +426,7 @@ export class SvgGenerationService {
465
426
// If line exists in modifiedLines as a key, process character diffs
466
427
if ( Array . from ( modifiedLines . keys ( ) ) . includes ( line ) ) {
467
428
const modifiedLine = modifiedLines . get ( line ) !
468
- const changes = diffChars ( line , modifiedLine )
429
+ const changes = diffWordsWithSpace ( line , modifiedLine )
469
430
470
431
let charPos = 0
471
432
for ( const part of changes ) {
@@ -497,7 +458,7 @@ export class SvgGenerationService {
497
458
498
459
if ( reverseMap . has ( line ) ) {
499
460
const originalLine = reverseMap . get ( line ) !
500
- const changes = diffChars ( originalLine , line )
461
+ const changes = diffWordsWithSpace ( originalLine , line )
501
462
502
463
let charPos = 0
503
464
for ( const part of changes ) {
@@ -522,12 +483,9 @@ export class SvgGenerationService {
522
483
}
523
484
}
524
485
525
- const mergedOriginalRanges = mergeAdjacentRanges ( originalRanges )
526
- const mergedAfterRanges = mergeAdjacentRanges ( afterRanges )
527
-
528
486
return {
529
- removedRanges : mergedOriginalRanges ,
530
- addedRanges : mergedAfterRanges ,
487
+ removedRanges : originalRanges ,
488
+ addedRanges : afterRanges ,
531
489
}
532
490
}
533
491
}
0 commit comments