@@ -202,7 +202,7 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
202202 }
203203 return . cursor( cursorPosition)
204204 } ( ) ,
205- modifications : extraInfo. modifications
205+ modifications: extraInfo. modifications
206206 )
207207 }
208208
@@ -347,24 +347,27 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
347347 presenter. markAsProcessing ( true )
348348 defer { presenter. markAsProcessing ( false ) }
349349 let fileURL = try await Environment . fetchCurrentFileURL ( )
350- let language = UserDefaults . shared. value ( for: \. chatGPTLanguage)
351350 let codeLanguage = languageIdentifierFromFileURL ( fileURL)
352- let code = {
353- guard let selection = editor. selections. last,
354- selection. start != selection. end else { return " " }
355- return editor. selectedCode ( in: selection)
356- } ( )
351+
352+ let ( code, selection) = {
353+ guard var selection = editor. selections. last,
354+ selection. start != selection. end
355+ else { return ( " " , . cursor( editor. cursorPosition) ) }
356+ // always start from char 0 so that it can keep the indentation.
357+ selection. start = . init( line: selection. start. line, character: 0 )
358+ return (
359+ editor. selectedCode ( in: selection) ,
360+ . init(
361+ start: . init( line: selection. start. line, character: selection. start. character) ,
362+ end: . init( line: selection. end. line, character: selection. end. character)
363+ )
364+ )
365+ } ( ) as ( String , CursorRange )
357366
358367 _ = await WidgetDataSource . shared. createPromptToCode (
359368 for: fileURL,
360369 code: code,
361- selectionRange: editor. selections. last. map { . init(
362- start: $0. start,
363- end: $0. end
364- ) } ?? . init(
365- start: editor. cursorPosition,
366- end: editor. cursorPosition
367- ) ,
370+ selectionRange: selection,
368371 language: codeLanguage
369372 )
370373
0 commit comments