@@ -14,6 +14,7 @@ public struct PresentingCodeSuggestion: Equatable {
1414 public var suggestionCount : Int
1515 public var currentSuggestionIndex : Int
1616 public var replacingRange : CursorRange
17+ public var replacingLines : [ String ]
1718 public var descriptions : [ CodeSuggestion . Description ]
1819
1920 public init (
@@ -23,6 +24,7 @@ public struct PresentingCodeSuggestion: Equatable {
2324 suggestionCount: Int ,
2425 currentSuggestionIndex: Int ,
2526 replacingRange: CursorRange ,
27+ replacingLines: [ String ] ,
2628 descriptions: [ CodeSuggestion . Description ] = [ ]
2729 ) {
2830 self . code = code
@@ -31,6 +33,7 @@ public struct PresentingCodeSuggestion: Equatable {
3133 self . suggestionCount = suggestionCount
3234 self . currentSuggestionIndex = currentSuggestionIndex
3335 self . replacingRange = replacingRange
36+ self . replacingLines = replacingLines
3437 self . descriptions = descriptions
3538 }
3639}
@@ -231,8 +234,10 @@ struct CodeBlockSuggestionPanel: View {
231234 originalCode: String ,
232235 dimmedCharacterCount: AsyncCodeBlock . DimmedCharacterCount
233236 ) {
234- let range = suggestion. replacingRange
235- let codeInRange = EditorInformation . code ( in: textCursorTracker. content. lines, inside: range)
237+ var range = suggestion. replacingRange
238+ range. end = . init( line: range. end. line - range. start. line, character: range. end. character)
239+ range. start = . init( line: 0 , character: range. start. character)
240+ let codeInRange = EditorInformation . code ( in: suggestion. replacingLines, inside: range)
236241 let leftover = {
237242 if range. end. line >= 0 , range. end. line < textCursorTracker. content. lines. endIndex {
238243 let lastLine = textCursorTracker. content. lines [ range. end. line]
@@ -253,7 +258,7 @@ struct CodeBlockSuggestionPanel: View {
253258
254259 let prefix = {
255260 if range. start. line >= 0 , range. start. line < textCursorTracker. content. lines. endIndex {
256- let firstLine = textCursorTracker . content . lines [ range. start. line]
261+ let firstLine = suggestion . replacingLines [ range. start. line]
257262 if range. start. character < firstLine. utf16. count {
258263 let endIndex = firstLine. utf16. index (
259264 firstLine. utf16. startIndex,
@@ -296,7 +301,8 @@ struct CodeBlockSuggestionPanel: View {
296301 startLineIndex: 8 ,
297302 suggestionCount: 2 ,
298303 currentSuggestionIndex: 0 ,
299- replacingRange: . outOfScope
304+ replacingRange: . outOfScope,
305+ replacingLines: [ ]
300306 ) , suggestionDisplayCompactMode: . init(
301307 wrappedValue: false ,
302308 " suggestionDisplayCompactMode " ,
@@ -325,7 +331,8 @@ struct CodeBlockSuggestionPanel: View {
325331 startLineIndex: 8 ,
326332 suggestionCount: 2 ,
327333 currentSuggestionIndex: 0 ,
328- replacingRange: . outOfScope
334+ replacingRange: . outOfScope,
335+ replacingLines: [ ]
329336 ) , suggestionDisplayCompactMode: . init(
330337 wrappedValue: true ,
331338 " suggestionDisplayCompactMode " ,
@@ -352,7 +359,8 @@ struct CodeBlockSuggestionPanel: View {
352359 startLineIndex: 8 ,
353360 suggestionCount: 2 ,
354361 currentSuggestionIndex: 0 ,
355- replacingRange: . outOfScope
362+ replacingRange: . outOfScope,
363+ replacingLines: [ ]
356364 ) )
357365 . preferredColorScheme ( . light)
358366 . frame ( width: 450 , height: 400 )
0 commit comments