I’ve got a simple test going on with an NSTextView that’s connected to a property in my script. Updating the contents of the text view by simply changing the value of the property is working fine, but I’m finding that whenever it’s updated the scroll jumps back up to the top. I’m adding text to the property/variable by way of AppleScript (set my viewData to my viewData & return & tData).
I’d like to have it work more like that log/console in Xcode where:
¢ If you’re scrolled all the way to the bottom and text is added to the end then it scrolls even more to reveal the new text.
¢ If you’re not scrolled to the bottom, then you remain (scrolled) where you are when text is added.
I have a feeling I’m going to have to use some NSString methods on it to begin with, but I don’t know if that’s going to effect the scroll jumping back up or not.
You need to use the NSTextView method scrollRangeToVisible_. So if your text view is textView, something like this:
set textStorage to textView's textStorage()
set newTextLength to textStorage's |length|() as integer
textView's scrollRangeToVisible_({|location|:newTextLength, |length|:0})
textView's setSelectedRange_({|location|:newTextLength, |length|:0})
You can skip a bit of that if you know the length of your data already.