@@ -7,6 +7,7 @@ import { diffWordsWithSpace, diffLines } from 'diff'
77import * as vscode from 'vscode'
88import { ToolkitError , getLogger } from 'aws-core-vscode/shared'
99import { diffUtilities } from 'aws-core-vscode/shared'
10+ import { stripCommonIndentation } from './stringUtils'
1011type Range = { line : number ; start : number ; end : number }
1112
1213const logger = getLogger ( 'nextEditPrediction' )
@@ -78,6 +79,7 @@ export class SvgGenerationService {
7879
7980 const highlightRanges = this . generateHighlightRanges ( removedLines , addedLines , modifiedLines )
8081 const diffAddedWithHighlight = this . getHighlightEdit ( addedLines , highlightRanges . addedRanges )
82+ const normalizedDiffLines = stripCommonIndentation ( diffAddedWithHighlight )
8183
8284 // Create SVG window, document, and container
8385 const window = createSVGWindow ( )
@@ -90,7 +92,7 @@ export class SvgGenerationService {
9092
9193 // Generate CSS for syntax highlighting HTML content based on theme
9294 const styles = this . generateStyles ( currentTheme )
93- const htmlContent = this . generateHtmlContent ( diffAddedWithHighlight , styles , offset )
95+ const htmlContent = this . generateHtmlContent ( normalizedDiffLines , styles , offset )
9496
9597 // Create foreignObject to embed HTML
9698 const foreignObject = draw . foreignObject ( width + offset , height )
@@ -162,6 +164,9 @@ export class SvgGenerationService {
162164 white-space: pre-wrap; /* Preserve whitespace */
163165 background-color: ${ diffAdded } ;
164166 }
167+ .diff-unchanged {
168+ white-space: pre-wrap; /* Preserve indentation for unchanged lines */
169+ }
165170 `
166171 }
167172
@@ -229,7 +234,7 @@ export class SvgGenerationService {
229234
230235 // If no ranges for this line, leave it as-is with HTML escaping
231236 if ( lineRanges . length === 0 ) {
232- result . push ( this . escapeHtml ( line ) )
237+ result . push ( `<span class="diff-unchanged"> ${ this . escapeHtml ( line ) } </span>` )
233238 continue
234239 }
235240
@@ -244,7 +249,7 @@ export class SvgGenerationService {
244249 // Add text before the current range (with HTML escaping)
245250 if ( range . start > currentPos ) {
246251 const beforeText = line . substring ( currentPos , range . start )
247- highlightedLine += this . escapeHtml ( beforeText )
252+ highlightedLine += `<span class="diff-unchanged"> ${ this . escapeHtml ( beforeText ) } </span>`
248253 }
249254
250255 // Add the highlighted part (with HTML escaping)
@@ -258,7 +263,7 @@ export class SvgGenerationService {
258263 // Add any remaining text after the last range (with HTML escaping)
259264 if ( currentPos < line . length ) {
260265 const afterText = line . substring ( currentPos )
261- highlightedLine += this . escapeHtml ( afterText )
266+ highlightedLine += `<span class="diff-unchanged"> ${ this . escapeHtml ( afterText ) } </span>`
262267 }
263268
264269 result . push ( highlightedLine )
0 commit comments