File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
Core/Sources/Service/SuggestionCommandHandler Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,16 @@ struct PseudoCommandHandler {
107107 . presentErrorMessage ( " Fail to set editor content. " )
108108 }
109109
110- if let oldPosition {
110+ if let cursor = result. newCursor {
111+ var range = convertCursorPositionToRange ( cursor, in: result. content)
112+ if let value = AXValueCreate ( . cfRange, & range) {
113+ AXUIElementSetAttributeValue (
114+ focusElement,
115+ kAXSelectedTextRangeAttribute as CFString ,
116+ value
117+ )
118+ }
119+ } else if let oldPosition {
111120 var range = CFRange (
112121 location: oldPosition. lowerBound,
113122 length: 0
@@ -199,6 +208,23 @@ private extension PseudoCommandHandler {
199208 usesTabsForIndentation: usesTabsForIndentation
200209 )
201210 }
211+
212+ // a function to convert CursorPosition(line:character:) into a Range(location:length) in given
213+ // content
214+ func convertCursorPositionToRange(
215+ _ cursorPosition: CursorPosition ,
216+ in content: String
217+ ) -> CFRange {
218+ let lines = content. breakLines ( )
219+ var count = 0
220+ for (i, line) in lines. enumerated ( ) {
221+ if i == cursorPosition. line {
222+ return CFRange ( location: count + cursorPosition. character, length: 0 )
223+ }
224+ count += line. count
225+ }
226+ return CFRange ( location: count, length: 0 )
227+ }
202228}
203229
204230public extension String {
You can’t perform that action at this time.
0 commit comments