0

I have a NSTextView to display long lines of numeric data, separated by tabs. I cannot prevent the line break after a fixed length. As a test. I use to Strings: Displaying a long line of pure textA works fine:
enter image description here
TextB breaks the line after 9 chunks: enter image description here My code: (downloadDataFeld is the NSTextView)

let textA = "asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh    \n"
let textB = "asdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \n"

let paragraphStyle = NSMutableParagraphStyle()
let tabInterval:CGFloat = 20.0
let tabs:NSMutableArray = NSMutableArray.init()

for cnt in 0..<24 
{    // Add 24 tab stops, at desired intervals...
   paragraphStyle.tabStops.append(NSTextTab(textAlignment: .left, location: (CGFloat(cnt) * tabInterval), options: [:]))
}

let attrtext = NSMutableAttributedString(string: textB)
let textRange = NSMakeRange(0, textB.characters.count)
attrtext.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: textRange)
// load the text
downloadDataFeld.textStorage?.append(attrtext)

The TextView settings are:
(I had to set the with of the documentView explicitly in code to get the working result without tabs)

downloadDataFeld.delegate = self
  downloadDataFeld.enclosingScrollView?.documentView?.frame.size.width = 2000 // muss
  downloadDataFeld.enclosingScrollView?.hasHorizontalScroller = true
  downloadDataFeld.enclosingScrollView?.hasVerticalScroller = true
  downloadDataFeld.enclosingScrollView?.autohidesScrollers = false

I couldn't find anything to set the line break. What am I missing?

heimi
  • 499
  • 7
  • 16
  • You're adding tab stops to the default tab stops and the tab stops are too close together. Show the ruler to see the tab stops. – Willeke Jul 25 '17 at 10:08
  • Thanks for the tip. removeAll() on tabstops did the trick. The tabIntervall is OK for uint8-Integers. – heimi Jul 25 '17 at 12:50

0 Answers0