私の構文強調表示の実装では、NSTextView
usingへの変更を観察し-[<NSTextStorageDelegate> textStorageDidProcessEditing:]
ます。
- (void)textStorageDidProcessEditing:(NSNotification *)notification {
if (!self.languageGrammar) return;
NSTextStorage *textStorage = self.textView.textStorage;
NSRange glyphRange = [self.textView.layoutManager glyphRangeForBoundingRect:self.scrollView.documentVisibleRect
inTextContainer:self.textView.textContainer];
NSRange editedRange = [self.textView.layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL];
[textStorage removeAttribute:NSForegroundColorAttributeName range:editedRange];
// crash is the line above ^^^^
// color text ...
}
表示可能な文字の範囲を取得したい。上記のコードはbackspace、ヒットするまで機能し、クラッシュします。
*** -[NSConcreteTextStorage attributesAtIndex:effectiveRange:]: Range or index out of bounds
表示される文字の範囲を取得して色を付けるにはどうすればよいですか?