This behavior can be easily seen in the /Developer/Examples/ Accessibility/AXCanvas sample code as well.

Basically, if one starts typing and proceeds to go beyond what the fieldEditor can display, the fieldEditor does not automatically scroll to keep the indicator visible.

Is there an easy way to do this?

I do see that textViewDidChangeSelection: does get called as I typing or use the arrow keys to move the cursor around. I thought I might be able to do the following:

- (void)textViewDidChangeSelection:(NSNotification *)aNotification
{
  NSRange selectedRange = [[aNotification object] selectedRange];       
  [[aNotification object] scrollRangeToVisible:selectedRange];
}

But, considering that a fieldEditor doesn't have a NSScrollView, I wasn't really expecting it to work.



Now, what I figure I can make work is something along the lines of:

- (void)textViewDidChangeSelection:(NSNotification *)aNotification
{
  NSRange selectedRange = [[aNotification object] selectedRange];
NSPoint locationOfSelection = [[[aNotification object] layoutManager] locationForGlyphAtIndex:selectedRange.location];
  [[aNotification object] setBoundsOrigin:locationOfSelection];
}

Basically:

1. obtain the selected range,
2. find the location of the selection
3. adjust the bounds origin of the fieldEditor to make sure the location of the indicator / insertion point is visible

Now, obviously, the code above doesn't do #3 yet, but it shouldn't be that difficult to accomplish.



Is there an easier way?

Perhaps, the 'right way' is to override windowWillReturnFieldEditor:toObject: to return a NSTextView which is inside of a NSScrollView?
_______________________________________________

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