Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

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:)

Hey! Can I ask how you implemented that with TextKit 2 in order to get other paragraphs to update?

Syntax Highlighting with TextKit 2
 
 
Q