Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/amazonq/src/app/inline/EditRendering/svgGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const emptyDiffSvg = {
originalCodeHighlightRange: [],
}

const defaultLineHighlightLength = 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we choose this number? This means 4 spaces are highlighted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we can only do a static rendering afaik, and the number 4 is alignment with product


export class SvgGenerationService {
/**
* Generates an SVG image representing a code diff
Expand Down Expand Up @@ -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)

Expand All @@ -455,7 +461,7 @@ export class SvgGenerationService {
originalRanges.push({
line: lineIndex,
start: 0,
end: line.length,
end: line.length ?? defaultLineHighlightLength,
})
}
}
Expand Down
Loading