@@ -136,47 +136,55 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
136136 func acceptSuggestion( editor: EditorContent ) async throws -> UpdatedContent ? {
137137 presenter. markAsProcessing ( true )
138138 defer { presenter. markAsProcessing ( false ) }
139-
139+
140140 let fileURL = try await Environment . fetchCurrentFileURL ( )
141141 let ( workspace, _) = try await Workspace . fetchOrCreateWorkspaceIfNeeded ( fileURL: fileURL)
142142
143- let result : ( suggestion: CopilotCompletion , cleanup: ( ) -> Void ) ? = {
143+ let result : (
144+ suggestion: CopilotCompletion ,
145+ cleanup: ( ) -> Void ,
146+ startPosition: CursorPosition ?
147+ ) ? = {
144148 if let service = WidgetDataSource . shared. promptToCodes [ fileURL] ? . promptToCodeService {
145- return ( CopilotCompletion (
146- text: service. code,
147- position: service. selectionRange. start,
148- uuid: UUID ( ) . uuidString,
149- range: service. selectionRange,
150- displayText: service. code
151- ) , {
152- WidgetDataSource . shared. removePromptToCode ( for: fileURL)
153- presenter. closePromptToCode ( fileURL: fileURL)
154- } )
149+ return (
150+ CopilotCompletion (
151+ text: service. code,
152+ position: service. selectionRange. start,
153+ uuid: UUID ( ) . uuidString,
154+ range: service. selectionRange,
155+ displayText: service. code
156+ ) ,
157+ {
158+ WidgetDataSource . shared. removePromptToCode ( for: fileURL)
159+ presenter. closePromptToCode ( fileURL: fileURL)
160+ } ,
161+ service. selectionRange. start
162+ )
155163 }
156-
164+
157165 if let acceptedSuggestion = workspace. acceptSuggestion (
158166 forFileAt: fileURL,
159167 editor: editor
160168 ) {
161- return ( acceptedSuggestion, {
162- presenter. discardSuggestion ( fileURL: fileURL)
163- } )
169+ return (
170+ acceptedSuggestion,
171+ {
172+ presenter. discardSuggestion ( fileURL: fileURL)
173+ } ,
174+ nil
175+ )
164176 }
165-
177+
166178 return nil
167179 } ( )
168-
180+
169181 guard let result else { return nil }
170-
182+
171183 let injector = SuggestionInjector ( )
172184 var lines = editor. lines
173185 var cursorPosition = editor. cursorPosition
174186 var extraInfo = SuggestionInjector . ExtraInfo ( )
175- injector. rejectCurrentSuggestions (
176- from: & lines,
177- cursorPosition: & cursorPosition,
178- extraInfo: & extraInfo
179- )
187+
180188 injector. acceptSuggestion (
181189 intoContentWithoutSuggestion: & lines,
182190 cursorPosition: & cursorPosition,
@@ -185,11 +193,16 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
185193 )
186194
187195 result. cleanup ( )
188-
196+
189197 return . init(
190198 content: String ( lines. joined ( separator: " " ) ) ,
191- newCursor: cursorPosition,
192- modifications: extraInfo. modifications
199+ newSelection: {
200+ if let startPosition = result. startPosition {
201+ return . init( start: startPosition, end: cursorPosition)
202+ }
203+ return . cursor( cursorPosition)
204+ } ( ) ,
205+ modifications : extraInfo. modifications
193206 )
194207 }
195208
0 commit comments