NSTextView does word-wrap by default. How can I disable this?
I’m making a JSON code viewer, so I have to disable this.
NSTextView does word-wrap by default. How can I disable this? I’m making a JSON
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, this document explains why and how — https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/TextStorageLayer/Tasks/TrackingSize.html#//apple_ref/doc/uid/20000927-CJBBIAAF
I got solution from: http://lists.apple.com/archives/cocoa-dev/2008/May/msg02396.html
You have to set NSTextView’s maximum width to very large number to make this work correctly. (Just copy maximum height)
And enable horizontal scrolling of NSScrollView which is superview of the NSTextView.
See these pictures:
http://www.flickr.com/photos/47601728@N06/4759470529/
http://www.flickr.com/photos/47601728@N06/4759470533/
Update
I discovered my old sample code was insufficient to make it fully work correctly. (because of SDK version?)
Also
Here’s my full source code snippet which disables word-wrap in OSX 10.8 SDK.
Update 2
Now Apple is providing an official guide to create
NSTextViewcorrectly. I hope this helps.Update 3
I posted an example project on Github. See this page for specific implementation: https://github.com/Eonil/CocoaProgrammaticHowtoCollection/blob/master/ComponentUsages/TextView/ExampleApplicationController.swift?ts=4
Here’s a code snippet from the sample project.