I implemented basic syntax highlighting by setting the NSTextStorage delegate of my NSTextView and changing the text attributes in -textStorageDidProcessEditing .
The main process is as follows
- (void)textStorageDidProcessEditing:(NSNotification *)notification { NSTextStorage *storage = [notification object]; [storage beginEditing]; NSString *text = [storage string]; NSRange textRange = NSMakeRange(0, [text length]); [storage removeAttribute:NSForegroundColorAttributeName range:textRange];
Whenever -removeAttribute:range: or -addAttribute:value:range is called when you enter the SPACE character, the location of the NSTextView surrounding NSScrollView starts to roll (the scroll knob moves to some random position nearby)
What causes this?
objective-c cocoa macos
Erik aigner
source share