Skip to content

Commit 724f3c2

Browse files
Merge master into feature/editable_diffview
2 parents f8f1415 + b4aae3f commit 724f3c2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export const emptyDiffSvg = {
1818
originalCodeHighlightRange: [],
1919
}
2020

21+
const defaultLineHighlightLength = 4
22+
2123
export class SvgGenerationService {
2224
/**
2325
* Generates an SVG image representing a code diff
@@ -431,8 +433,12 @@ export class SvgGenerationService {
431433
for (let lineIndex = 0; lineIndex < originalCode.length; lineIndex++) {
432434
const line = originalCode[lineIndex]
433435

436+
/**
437+
* If [line] is an empty line or only contains whitespace char, [diffWordsWithSpace] will say it's not an "remove", i.e. [part.removed] will be undefined,
438+
* therefore the deletion will not be highlighted. Thus fallback this scenario to highlight the entire line
439+
*/
434440
// If line exists in modifiedLines as a key, process character diffs
435-
if (Array.from(modifiedLines.keys()).includes(line)) {
441+
if (Array.from(modifiedLines.keys()).includes(line) && line.trim().length > 0) {
436442
const modifiedLine = modifiedLines.get(line)!
437443
const changes = diffWordsWithSpace(line, modifiedLine)
438444

@@ -455,7 +461,7 @@ export class SvgGenerationService {
455461
originalRanges.push({
456462
line: lineIndex,
457463
start: 0,
458-
end: line.length,
464+
end: line.length ?? defaultLineHighlightLength,
459465
})
460466
}
461467
}

0 commit comments

Comments
 (0)