Colas
Colas

Reputation: 3573

How do I scroll to the cursor position in an NSTextView?

How can I make programmatically an NSTextView scroll to the cursor position?

Upvotes: 1

Views: 853

Answers (1)

Colas
Colas

Reputation: 3573

This should work

NSUInteger cursorPosition;
cursorPosition = [[[self.textView selectedRanges] firstObject] rangeValue].location;
[self.textView scrollRangeToVisible:NSMakeRange(cursorPosition, 0)];

Upvotes: 3

Related Questions