Is your feature request related to a problem? Please describe.
TextView currently supports converting offset (Int) to line/column (TextLocation). With this API we could build our own Line/Column status, but if we have a Line/Column there is no API to help convert it to offset.
Describe the solution you'd like
We can have an override of textLocation API so embedders can covert between offset and line/column with the same method.
public func textLocation(at location: Int) -> TextLocation? {
if let linePosition = textInputView.linePosition(at: location) {
return TextLocation(linePosition)
} else {
return nil
}
}
+ public func textLocation(at textLocation: TextLocation) -> Int? {
+ let lineIndex = textLocation.lineNumber
+
+ guard lineIndex >= 0 && lineIndex < textInputView.lineManager.lineCount else {
+ return nil
+ }
+
+ let line = textInputView.lineManager.line(atRow: lineIndex)
+ return line.location + textLocation.column
+ }
Describe alternatives you've considered
Without this we would need to either calculate line ends ourselves or introduce "proxy functions" (like GoToLine).
Is your feature request related to a problem? Please describe.
TextViewcurrently supports converting offset (Int) to line/column (TextLocation). With this API we could build our own Line/Column status, but if we have a Line/Column there is no API to help convert it to offset.Describe the solution you'd like
We can have an override of
textLocationAPI so embedders can covert between offset and line/column with the same method.public func textLocation(at location: Int) -> TextLocation? { if let linePosition = textInputView.linePosition(at: location) { return TextLocation(linePosition) } else { return nil } } + public func textLocation(at textLocation: TextLocation) -> Int? { + let lineIndex = textLocation.lineNumber + + guard lineIndex >= 0 && lineIndex < textInputView.lineManager.lineCount else { + return nil + } + + let line = textInputView.lineManager.line(atRow: lineIndex) + return line.location + textLocation.column + }Describe alternatives you've considered
Without this we would need to either calculate line ends ourselves or introduce "proxy functions" (like
GoToLine).