Skip to content

Commit 88119f6

Browse files
committed
fix(amazonq): use diffWordsWithSpace instead of diffChars to calculate highlightedRanges
1 parent 62fab80 commit 88119f6

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

packages/amazonq/src/app/inline/EditRendering/svgGenerator.ts

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { diffChars } from 'diff'
6+
import { diffWordsWithSpace } from 'diff'
77
import * as vscode from 'vscode'
88
import { ToolkitError, getLogger } from 'aws-core-vscode/shared'
99
import { diffUtilities } from 'aws-core-vscode/shared'
@@ -416,41 +416,41 @@ export class SvgGenerationService {
416416
/**
417417
* Merges ranges on the same line that are separated by only one character
418418
*/
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-
}
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+
// }
454454

455455
// Create reverse mapping for quicker lookups
456456
const reverseMap = new Map<string, string>()
@@ -465,7 +465,7 @@ export class SvgGenerationService {
465465
// If line exists in modifiedLines as a key, process character diffs
466466
if (Array.from(modifiedLines.keys()).includes(line)) {
467467
const modifiedLine = modifiedLines.get(line)!
468-
const changes = diffChars(line, modifiedLine)
468+
const changes = diffWordsWithSpace(line, modifiedLine)
469469

470470
let charPos = 0
471471
for (const part of changes) {
@@ -497,7 +497,7 @@ export class SvgGenerationService {
497497

498498
if (reverseMap.has(line)) {
499499
const originalLine = reverseMap.get(line)!
500-
const changes = diffChars(originalLine, line)
500+
const changes = diffWordsWithSpace(originalLine, line)
501501

502502
let charPos = 0
503503
for (const part of changes) {
@@ -522,12 +522,12 @@ export class SvgGenerationService {
522522
}
523523
}
524524

525-
const mergedOriginalRanges = mergeAdjacentRanges(originalRanges)
526-
const mergedAfterRanges = mergeAdjacentRanges(afterRanges)
525+
// const mergedOriginalRanges = mergeAdjacentRanges(originalRanges)
526+
// const mergedAfterRanges = mergeAdjacentRanges(afterRanges)
527527

528528
return {
529-
removedRanges: mergedOriginalRanges,
530-
addedRanges: mergedAfterRanges,
529+
removedRanges: originalRanges,
530+
addedRanges: afterRanges,
531531
}
532532
}
533533
}

0 commit comments

Comments
 (0)