Remove character range from NSTextStorage, but keep coloring the rest correct?

759 Views Asked by At

I want to apply the same coloring of a NSTextView_A text to another NSTextView_B text, with just a fragment of the text of NSTextView_A.

I applied the NSTextView_A text coloring to NSTextView_B with NSLayoutManagerDelegate and

- (NSDictionary *)layoutManager:(NSLayoutManager *)layoutManager shouldUseTemporaryAttributes:    (NSDictionary *)attrs forDrawingToScreen:(BOOL)toScreen atCharacterIndex:(NSUInteger)charIndex effectiveRange:(NSRangePointer)effectiveCharRange

and then i deleted a character range in NSTextView_B text with:

[[_sourceCodeTextView textStorage]beginEditing];
[[_sourceCodeTextView textStorage]deleteCharactersInRange:    NSMakeRange(0, 253)];
[[_sourceCodeTextView textStorage]endEditing];

as described in Changing Text Storage

The problem now is, that the characters get deleted correctly, but the coloring of the text before deletion is applied without respecting the new range.

As an example: NSTextView_A text is blue in range 0-253 and e.g. everything behind green. After i delete the characters in NSTextView_B text (0-253), the resulting text is blue and afterwards green, but not just green.

How can i make the coloring to respect the new text fragment?

0

There are 0 best solutions below