Re: NSTextStorage insertion point
Re: NSTextStorage insertion point
- Subject: Re: NSTextStorage insertion point
- From: Gideon King <email@hidden>
- Date: Wed, 24 Mar 2010 09:45:23 +1000
I had this problem too, and in the end, I found a solution which was to make sure I had completed my updates of the text, and in my textStorageDidProcessEditing: method, I add the following:
[[NSRunLoop currentRunLoop] performSelector:@selector(updateSelectedRange:) target:self.editingView argument:NSStringFromRange(NSMakeRange(ts.newCaratLocation, 0)) order:0 modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
Where I have this method on the view:
- (void)updateSelectedRange:(NSString *)rangeString {
[self setSelectedRange:NSRangeFromString(rangeString)];
}
I found that I had to do it this way because calling it directly from the textStorageDidProcessEditing: method didn't work, and performWith...afterDelay didn't move the cursor to where you wanted it when you were typing fast. I also found that I needed to get it to update its typing attributes based on the new selection.
Hope this helps.
Regards
Gideon
On 24/03/2010, at 6:04 AM, Ben wrote:
> Hi list.
>
> I've got an NSTextView subclass which implements the NSTextStorage delegate method -textStorageWillProcessEditing:. In that method I do syntax highlighting and also replace certain substrings with text attachments (a bit like Xcode's autocomplete placeholders).
>
> The problem is that the insertion point is always moved to the end of the text view each time this method is invoked. It seems to happen whenever I modify the attributes of the text, not when I modify the text contents.
>
> Storing the insertion point and restoring it at the end of -textStorageWillProcessEditing or in -textStorageDidProcessEditing still result in the insertion point being moved to the end sometime later. There are other threads online with this problem, but they are old and have no solutions.
>
> Does anyone have any suggestions on how to avoid or work around this problem?
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden