NSTextStorage question and NSTextView "bug"(?)
NSTextStorage question and NSTextView "bug"(?)
- Subject: NSTextStorage question and NSTextView "bug"(?)
- From: "Stephan" <email@hidden>
- Date: Tue, 30 Apr 2002 19:03:36 +0200
Hello,
Question:
- how to modify attributes of a NSTextStorage outside of [myTextStorage
editedRange] without moving the insertion point?
Explanation:
I am currently trying to get some syntax highlighting done in an NSTextView.
I registered some controller of mine as the delegate of the NSTextStorage
for doing it. I implemented that highlighting in
- (void)textStorageWillProcessEditing:(NSNotification*)notification
The first problem encountered is that whenever I do a [myTextStorage
setAttributes:range] with a range outside of the [myTextStorage
editedRange], the insertion point (selectedRange) moves from where it was
(although I changed only the attributes), more commonly to the end of the
line or the end of the text... This is extremely painful as sometimes
highlighting is caused by the appearance of an element in the beginning of a
"block" like you expect whatever is after it to turn "green" when you type
/* in a C/ObjC/C++ editor.
While trying to find a solution I tried this:
selectedRange = [myTextView selectedRange];
[self performHighlightingInRange:[myTextStorage editedRange]];
[myTextView setSelectedRange:selectedRange];
This doesn't work because the selected range seems to be modified after the
execution of storageWillProcessEditing (and after storageDidProcessEditing
too).
But this showed that whenever I hit backspace in my textView and delete a
character, there seems to be an inconsistency in this that the returned
selectedRange is after NSMaxRange of the [NSTextStorage length] so I cannot
just store it and set it back later.
( for instance, I type 5 characters then hit backspace, selectedRange
returns Range.location = 5, but [myTextStorage length] returns 4). This is
bad because I personally expect [obj setter:[obj getter]]; to work...
Do any of you know:
Where I should perform my highlighting? (the documentation says in
storageWillProcessEditing)
Where can I change the selected range while being sure it happens after the
syntax highlighting and other operations I may want to perform (such as
autocompletion)?
Thanks for your time.
Stephan Pirson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.