1

I'd like to have custom line wrapping behavior for subranges of text in my NSTextView. Specifically, I'd like lines that look like list items (start with zero or more characters of leading whitespace, then a bullet character, then a space, then a non-space character) to wrap so that lines after the first line are indented two spaces right of the bullet.

I believe I can do this by setting an NSParagraphStyle on the subrange of text that represents the list item with a headIndent calculated to be the proper distance.

Beyond that, I don't know how to proceed. Where do I hook in to NSTextView to set this? How do I maintain (set, update, or remove) the NSParagraphStyle attribute and subrange as the user edits the text? This is an NSTextView so the text can be edited, copy/pasted, or read in from a file.

Is there a general (and performant) method for applying and maintaining attributes to subranges of text in an NSTextView?

sam
  • 3,399
  • 4
  • 36
  • 51

0 Answers0