diff --git a/packages/amazonq/src/app/inline/EditRendering/svgGenerator.ts b/packages/amazonq/src/app/inline/EditRendering/svgGenerator.ts index 6958be47f36..21293c3d577 100644 --- a/packages/amazonq/src/app/inline/EditRendering/svgGenerator.ts +++ b/packages/amazonq/src/app/inline/EditRendering/svgGenerator.ts @@ -18,6 +18,8 @@ export const emptyDiffSvg = { originalCodeHighlightRange: [], } +const defaultLineHighlightLength = 4 + export class SvgGenerationService { /** * Generates an SVG image representing a code diff @@ -431,8 +433,12 @@ export class SvgGenerationService { for (let lineIndex = 0; lineIndex < originalCode.length; lineIndex++) { const line = originalCode[lineIndex] + /** + * 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, + * therefore the deletion will not be highlighted. Thus fallback this scenario to highlight the entire line + */ // If line exists in modifiedLines as a key, process character diffs - if (Array.from(modifiedLines.keys()).includes(line)) { + if (Array.from(modifiedLines.keys()).includes(line) && line.trim().length > 0) { const modifiedLine = modifiedLines.get(line)! const changes = diffWordsWithSpace(line, modifiedLine) @@ -455,7 +461,7 @@ export class SvgGenerationService { originalRanges.push({ line: lineIndex, start: 0, - end: line.length, + end: line.length ?? defaultLineHighlightLength, }) } }