How to disable scrolling in NSTextView for macOS

Issue #733

NSTextView has this handy method to make scrollable NSTextView NSTextView.scrollableTextView(). The solution is to get to the responder outside enclosing NSScrollView, in my case it is the SwiftUI hosting view

1
2
3
4
5
6
7
8
9
class DisabledScrollTextView: NSTextView {
override func scrollWheel(with event: NSEvent)
{
// 1st nextResponder is NSClipView
// 2nd nextResponder is NSScrollView
// 3rd nextResponder is NSResponder SwiftUIPlatformViewHost
self.nextResponder?.nextResponder?.nextResponder?.scrollWheel(with: event)
}
}

Then we can construct with our new DisabledScrollTextView.scrollableTextView

Updated at 2020-12-31 07:45:19

Comments