@@ -23,6 +23,7 @@ struct PseudoCommandHandler {
2323 lines: [ ] ,
2424 uti: " " ,
2525 cursorPosition: . outOfScope,
26+ cursorOffset: - 1 ,
2627 selections: [ ] ,
2728 tabSize: 0 ,
2829 indentSize: 0 ,
@@ -37,6 +38,7 @@ struct PseudoCommandHandler {
3738 lines: [ ] ,
3839 uti: " " ,
3940 cursorPosition: . outOfScope,
41+ cursorOffset: - 1 ,
4042 selections: [ ] ,
4143 tabSize: 0 ,
4244 indentSize: 0 ,
@@ -128,6 +130,7 @@ struct PseudoCommandHandler {
128130 lines: [ ] ,
129131 uti: " " ,
130132 cursorPosition: . outOfScope,
133+ cursorOffset: - 1 ,
131134 selections: [ ] ,
132135 tabSize: 0 ,
133136 indentSize: 0 ,
@@ -148,6 +151,7 @@ struct PseudoCommandHandler {
148151 lines: [ ] ,
149152 uti: " " ,
150153 cursorPosition: . outOfScope,
154+ cursorOffset: - 1 ,
151155 selections: [ ] ,
152156 tabSize: 0 ,
153157 indentSize: 0 ,
@@ -206,7 +210,7 @@ struct PseudoCommandHandler {
206210 guard let focusElement = application. focusedElement,
207211 focusElement. description == " Source Editor "
208212 else { return }
209- guard let ( content, lines, _, cursorPosition) = await getFileContent ( sourceEditor: nil )
213+ guard let ( content, lines, _, cursorPosition, cursorOffset ) = await getFileContent ( sourceEditor: nil )
210214 else {
211215 PresentInWindowSuggestionPresenter ( )
212216 . presentErrorMessage ( " Unable to get file content. " )
@@ -219,6 +223,7 @@ struct PseudoCommandHandler {
219223 lines: lines,
220224 uti: " " ,
221225 cursorPosition: cursorPosition,
226+ cursorOffset: cursorOffset,
222227 selections: [ ] ,
223228 tabSize: 0 ,
224229 indentSize: 0 ,
@@ -261,7 +266,7 @@ struct PseudoCommandHandler {
261266 guard let focusElement = application. focusedElement,
262267 focusElement. description == " Source Editor "
263268 else { return }
264- guard let ( content, lines, _, cursorPosition) = await getFileContent ( sourceEditor: nil )
269+ guard let ( content, lines, _, cursorPosition, cursorOffset ) = await getFileContent ( sourceEditor: nil )
265270 else {
266271 PresentInWindowSuggestionPresenter ( )
267272 . presentErrorMessage ( " Unable to get file content. " )
@@ -274,6 +279,7 @@ struct PseudoCommandHandler {
274279 lines: lines,
275280 uti: " " ,
276281 cursorPosition: cursorPosition,
282+ cursorOffset: cursorOffset,
277283 selections: [ ] ,
278284 tabSize: 0 ,
279285 indentSize: 0 ,
@@ -361,7 +367,8 @@ extension PseudoCommandHandler {
361367 content: String ,
362368 lines: [ String ] ,
363369 selections: [ CursorRange ] ,
364- cursorPosition: CursorPosition
370+ cursorPosition: CursorPosition ,
371+ cursorOffset: Int
365372 ) ?
366373 {
367374 guard let xcode = ActiveApplicationMonitor . shared. activeXcode
@@ -374,7 +381,7 @@ extension PseudoCommandHandler {
374381 let content = focusElement. value
375382 let split = content. breakLines ( appendLineBreakToLastLine: false )
376383 let range = convertRangeToCursorRange ( selectionRange, in: content)
377- return ( content, split, [ range] , range. start)
384+ return ( content, split, [ range] , range. start, selectionRange . lowerBound )
378385 }
379386
380387 func getFileURL( ) async -> URL ? {
@@ -410,6 +417,7 @@ extension PseudoCommandHandler {
410417 lines: content. lines,
411418 uti: uti,
412419 cursorPosition: content. cursorPosition,
420+ cursorOffset: content. cursorOffset,
413421 selections: content. selections. map {
414422 . init( start: $0. start, end: $0. end)
415423 } ,
0 commit comments