When moving from line to line in a textview with "up" and "down" keys, it exhibits this scrolling behavior - when the cursor is at the very top and I hit "up" (and vice versa), it scrolls the document half page up, that is, the current line is now in the middle of the textview.
Is it possible to disable this behavior? Is it possible to make it scroll by just one line? So that the current line stays always at the top (or bottom)?
I know I come a little late to the party, but since this hasn't been properly answered, I'll give it a try. I had the same problem with NSTextViews. When using -scrollRangeToVisible to bring the insert position to the visible rect of the view, it had this habit of scrolling as to put the caret in the (vertical)middle of the screen. What I did was use [NSView scrollRectToVisible] instead, as it scrolls the minimum distance needed to bring a rect to the visible rect of the view:
NSRange caretRng = NSMakeRange(caretLocation, 0);
NSLayoutManager* lm = [view layoutManager];
NSRange glyphRange = [lm glyphRangeForCharacterRange:caretRng actualCharacterRange:nil];
NSRect glyphRect = [lm boundingRectForGlyphRange:glyphRange inTextContainer:[view textContainer]];
[view scrollRectToVisible:glyphRect];
Hope it helps!
NSTextView (via NSText) has a method called -scrollRangeToVisible:. Consider subclassing NSTextView and overriding -scrollRangeToVisible to specify your own scrolling behavior directly.
If you need more specific help with getting the behavior right, post a separate question specifying exactly the behavior you want and the code you tried to get it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With