@@ -197,16 +197,25 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
197197 return nil
198198 }
199199
200- let rangeStart = promptToCode. selectionRange? . start ?? editor. cursorPosition
200+ let range = {
201+ if promptToCode. isAttachedToSelectionRange,
202+ let range = promptToCode. selectionRange
203+ {
204+ return range
205+ }
206+ return editor. selections. first. map {
207+ CursorRange ( start: $0. start, end: $0. end)
208+ } ?? CursorRange (
209+ start: editor. cursorPosition,
210+ end: editor. cursorPosition
211+ )
212+ } ( )
201213
202214 let suggestion = CodeSuggestion (
203215 text: promptToCode. code,
204- position: rangeStart ,
216+ position: range . start ,
205217 uuid: UUID ( ) . uuidString,
206- range: promptToCode. selectionRange ?? . init(
207- start: editor. cursorPosition,
208- end: editor. cursorPosition
209- ) ,
218+ range: range,
210219 displayText: promptToCode. code
211220 )
212221
@@ -217,11 +226,11 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
217226 extraInfo: & extraInfo
218227 )
219228
220- _ = await Task { @MainActor [ cursorPosition] in
229+ _ = await Task { @MainActor [ cursorPosition] in
221230 viewStore. send (
222231 . promptToCodeGroup( . updatePromptToCodeRange(
223232 id: promptToCode. id,
224- range: . init( start: rangeStart , end: cursorPosition)
233+ range: . init( start: range . start , end: cursorPosition)
225234 ) )
226235 )
227236 viewStore. send (
@@ -233,7 +242,7 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
233242
234243 return . init(
235244 content: String ( lines. joined ( separator: " " ) ) ,
236- newSelection: . init( start: rangeStart , end: cursorPosition) ,
245+ newSelection: . init( start: range . start , end: cursorPosition) ,
237246 modifications: extraInfo. modifications
238247 )
239248 }
0 commit comments