0

I have tried the answers in How to disable word-wrap of NSTextView? for half a day but have had no luck. The answers were a bit scattered and confusing really.

I have this code:

@IBOutlet var display: NSTextView!

func applicationDidFinishLaunching(aNotification: NSNotification) {
    // Insert code here to initialize your application
    let LargeNumberForText: CGFloat = 1.0e7
    display.textContainer!.containerSize = NSMakeSize(LargeNumberForText, LargeNumberForText)
    display.textContainer!.widthTracksTextView = false
    display.horizontallyResizable = true
    display.autoresizingMask = [.ViewWidthSizable, .ViewHeightSizable]
}

and I have this in the .xib: NSTextView size settings

Did I miss a step?

Community
  • 1
  • 1
Richard Birkett
  • 771
  • 9
  • 20

1 Answers1

0

My issue was in fact Premature line wrapping in NSTextView when tabs are used I corrected the issue by employing both the word-wrap code above, and calling this after changing the text:

func format() {
    let numStops = 100000;
    let tabInterval = 40;
    var tabStop: NSTextTab

    //attributes for attributed String of TextView

    let paraStyle = NSMutableParagraphStyle()

    // This first clears all tab stops, then adds tab stops, at desired intervals...
    paraStyle.tabStops = []
    for cnt in 1...numStops {
        tabStop = NSTextTab(type: .LeftTabStopType, location: CGFloat(tabInterval * cnt))
        paraStyle.addTabStop(tabStop)
    }

    var attrs = [String: AnyObject]()
    attrs.updateValue(paraStyle, forKey:NSParagraphStyleAttributeName)

    display.textStorage!.addAttributes(attrs, range: NSMakeRange(0, display.textStorage!.string.characters.count))
}

where display is the NSTextView. Subclassing would be more elegant of course.

Community
  • 1
  • 1
Richard Birkett
  • 771
  • 9
  • 20