@@ -47,8 +47,8 @@ extension TextViewController {
4747 continue
4848 }
4949 let column = ( selectedRange. range. location - linePosition. range. location) + 1
50- let row = linePosition. index + 1
51- positions. append ( CursorPosition ( range: selectedRange. range, line: row , column: column) )
50+ let line = linePosition. index + 1
51+ positions. append ( CursorPosition ( range: selectedRange. range, line: line , column: column) )
5252 }
5353
5454 isPostingCursorNotification = true
@@ -58,5 +58,34 @@ extension TextViewController {
5858 coordinator. textViewDidChangeSelection ( controller: self , newPositions: cursorPositions)
5959 }
6060 isPostingCursorNotification = false
61+
62+ if let completionDelegate = completionDelegate, let position = cursorPositions. first {
63+ SuggestionController . shared. cursorsUpdated ( textView: self , delegate: completionDelegate, position: position)
64+ }
65+ }
66+
67+ /// Fills out all properties on the given cursor position if it's missing either the range or line/column
68+ /// information.
69+ func resolveCursorPosition( _ position: CursorPosition ) -> CursorPosition ? {
70+ var range = position. range
71+ if range == . notFound {
72+ guard position. line > 0 , position. column > 0 ,
73+ let linePosition = textView. layoutManager. textLineForIndex ( position. line - 1 ) else {
74+ return nil
75+ }
76+ range = NSRange ( location: linePosition. range. location + position. column, length: 0 )
77+ }
78+
79+ var line = position. line
80+ var column = position. column
81+ if position. line <= 0 || position. column <= 0 {
82+ guard range != . notFound, let linePosition = textView. layoutManager. textLineForOffset ( range. location) else {
83+ return nil
84+ }
85+ column = ( range. location - linePosition. range. location) + 1
86+ line = linePosition. index + 1
87+ }
88+
89+ return CursorPosition ( range: range, line: line, column: column)
6190 }
6291}
0 commit comments