33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import { diffChars } from 'diff'
6+ import { diffWordsWithSpace } from 'diff'
77import * as vscode from 'vscode'
88import { ToolkitError , getLogger } from 'aws-core-vscode/shared'
99import { diffUtilities } from 'aws-core-vscode/shared'
@@ -413,45 +413,6 @@ export class SvgGenerationService {
413413 const originalRanges : Range [ ] = [ ]
414414 const afterRanges : Range [ ] = [ ]
415415
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-
455416 // Create reverse mapping for quicker lookups
456417 const reverseMap = new Map < string , string > ( )
457418 for ( const [ original , modified ] of modifiedLines . entries ( ) ) {
@@ -465,7 +426,7 @@ export class SvgGenerationService {
465426 // If line exists in modifiedLines as a key, process character diffs
466427 if ( Array . from ( modifiedLines . keys ( ) ) . includes ( line ) ) {
467428 const modifiedLine = modifiedLines . get ( line ) !
468- const changes = diffChars ( line , modifiedLine )
429+ const changes = diffWordsWithSpace ( line , modifiedLine )
469430
470431 let charPos = 0
471432 for ( const part of changes ) {
@@ -497,7 +458,7 @@ export class SvgGenerationService {
497458
498459 if ( reverseMap . has ( line ) ) {
499460 const originalLine = reverseMap . get ( line ) !
500- const changes = diffChars ( originalLine , line )
461+ const changes = diffWordsWithSpace ( originalLine , line )
501462
502463 let charPos = 0
503464 for ( const part of changes ) {
@@ -522,12 +483,9 @@ export class SvgGenerationService {
522483 }
523484 }
524485
525- const mergedOriginalRanges = mergeAdjacentRanges ( originalRanges )
526- const mergedAfterRanges = mergeAdjacentRanges ( afterRanges )
527-
528486 return {
529- removedRanges : mergedOriginalRanges ,
530- addedRanges : mergedAfterRanges ,
487+ removedRanges : originalRanges ,
488+ addedRanges : afterRanges ,
531489 }
532490 }
533491}
0 commit comments