Syntax Highlighting with TextKit 2

Based on this TextKit 2 demo project I thought that I could implement syntax highlighting by parsing syntax block tokens (e.g. comments like <!-- --> or /* */) in processEditing and storing their locations, and then actually applying the rendering with NSTextContentStorageDelegate in textContentStorage(_:textParagraphWith:) by checking the location of each paragraph against the store of syntax tokens.

This sort of works except that the rendering is only updated for paragraphs which are changed.

Is there a way to trigger NSTextContentStorage to re-fetch paragraphs in a given range? Or is this a totally misguided approach to the problem?

Answered by grraham in 803763022

The method I wanted was NSTextStorage edited(_:range:changeInLength:)

Accepted Answer

The method I wanted was NSTextStorage edited(_:range:changeInLength:)

Syntax Highlighting with TextKit 2
 
 
Q