1

NSTextView_A のテキストの断片だけを使用して、NSTextView_A テキストの同じ色を別の NSTextView_B テキストに適用したいと考えています。

NSTextView_A のテキスト カラーリングを NSTextView_B に NSLayoutManagerDelegate で適用し、

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

次に、NSTextView_B テキストの文字範囲を次のように削除しました。

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

テキストストレージの変更で説明されているように

問題は、文字が正しく削除されることですが、削除前のテキストの色付けが新しい範囲を尊重せずに適用されることです。

例: NSTextView_A のテキストは 0 ~ 253 の範囲では青で、たとえばすべて緑の背後にあります。NSTextView_B テキスト (0-253) の文字を削除した後、結果のテキストは青になり、その後緑になりますが、緑だけではありません。

新しいテキストフラグメントを尊重するように色を付けるにはどうすればよいですか?

4

0 に答える 0