I'm trying to figure out how I can scroll to bottom and only scroll to bottom if the scroll position is at the bottom, like XCODE.
I can't figure out how I can get the current scroll position of an NSTextView.
It's simple to just scroll to the bottom using:
self.tbLog.scrollToEndOfDocument(nil)
But this happens every time and if you are scrolled up to the top of a log file and a new line is added, it drops back to the bottom. I only want to drop to the bottom if the scroll position is at the bottom.
SOLUTION:
// Add your text to the NSTextView here... then...
print("Position: \(NSMaxY(self.tbLog.visibleRect) - NSMaxY(self.tbLog.bounds))")
if (NSMaxY(self.tbLog.visibleRect) - NSMaxY(self.tbLog.bounds) == 0.0) {
print("we're at the bottom, keep at the bottom.")
self.tbLog.scrollToEndOfDocument(nil)
} else {
print("we're scrolled up somewhere... do nothing.")
}