@@ -7,6 +7,7 @@ import { diffWordsWithSpace, diffLines } from 'diff'
7
7
import * as vscode from 'vscode'
8
8
import { ToolkitError , getLogger } from 'aws-core-vscode/shared'
9
9
import { diffUtilities } from 'aws-core-vscode/shared'
10
+ import { stripCommonIndentation } from './stringUtils'
10
11
type Range = { line : number ; start : number ; end : number }
11
12
12
13
const logger = getLogger ( 'nextEditPrediction' )
@@ -78,6 +79,7 @@ export class SvgGenerationService {
78
79
79
80
const highlightRanges = this . generateHighlightRanges ( removedLines , addedLines , modifiedLines )
80
81
const diffAddedWithHighlight = this . getHighlightEdit ( addedLines , highlightRanges . addedRanges )
82
+ const normalizedDiffLines = stripCommonIndentation ( diffAddedWithHighlight )
81
83
82
84
// Create SVG window, document, and container
83
85
const window = createSVGWindow ( )
@@ -90,7 +92,7 @@ export class SvgGenerationService {
90
92
91
93
// Generate CSS for syntax highlighting HTML content based on theme
92
94
const styles = this . generateStyles ( currentTheme )
93
- const htmlContent = this . generateHtmlContent ( diffAddedWithHighlight , styles , offset )
95
+ const htmlContent = this . generateHtmlContent ( normalizedDiffLines , styles , offset )
94
96
95
97
// Create foreignObject to embed HTML
96
98
const foreignObject = draw . foreignObject ( width + offset , height )
@@ -162,6 +164,9 @@ export class SvgGenerationService {
162
164
white-space: pre-wrap; /* Preserve whitespace */
163
165
background-color: ${ diffAdded } ;
164
166
}
167
+ .diff-unchanged {
168
+ white-space: pre-wrap; /* Preserve indentation for unchanged lines */
169
+ }
165
170
`
166
171
}
167
172
@@ -229,7 +234,7 @@ export class SvgGenerationService {
229
234
230
235
// If no ranges for this line, leave it as-is with HTML escaping
231
236
if ( lineRanges . length === 0 ) {
232
- result . push ( this . escapeHtml ( line ) )
237
+ result . push ( `<span class="diff-unchanged"> ${ this . escapeHtml ( line ) } </span>` )
233
238
continue
234
239
}
235
240
@@ -244,7 +249,7 @@ export class SvgGenerationService {
244
249
// Add text before the current range (with HTML escaping)
245
250
if ( range . start > currentPos ) {
246
251
const beforeText = line . substring ( currentPos , range . start )
247
- highlightedLine += this . escapeHtml ( beforeText )
252
+ highlightedLine += `<span class="diff-unchanged"> ${ this . escapeHtml ( beforeText ) } </span>`
248
253
}
249
254
250
255
// Add the highlighted part (with HTML escaping)
@@ -258,7 +263,7 @@ export class SvgGenerationService {
258
263
// Add any remaining text after the last range (with HTML escaping)
259
264
if ( currentPos < line . length ) {
260
265
const afterText = line . substring ( currentPos )
261
- highlightedLine += this . escapeHtml ( afterText )
266
+ highlightedLine += `<span class="diff-unchanged"> ${ this . escapeHtml ( afterText ) } </span>`
262
267
}
263
268
264
269
result . push ( highlightedLine )
0 commit comments