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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to