Re: fieldEditor not scrolling to keep insertion point / indicator visible
Re: fieldEditor not scrolling to keep insertion point / indicator visible
- Subject: Re: fieldEditor not scrolling to keep insertion point / indicator visible
- From: Eric Gorr <email@hidden>
- Date: Tue, 3 Mar 2009 17:36:35 -0500
On Mar 3, 2009, at 2:42 PM, Eric Gorr wrote:
On Mar 3, 2009, at 1:04 PM, Eric Gorr wrote:
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.
Actually, this won't work. After thinking about it for a few more
seconds, it would seem difficult (at best) to determine where to
scroll to if the user is click-and-dragging to select some text.
What I just tried (and it still doesn't work) is to create my own
NSScrollView for the fieldEditor...
fieldEditorScroller = [[NSScrollView alloc] initWithFrame:[self
bounds]];
[fieldEditorScroller setHasVerticalRuler:NO];
[fieldEditorScroller setHasHorizontalRuler:NO];
[fieldEditorScroller setHasVerticalScroller:NO];
[fieldEditorScroller setHasHorizontalScroller:NO];
[fieldEditorScroller setBorderType:NSNoBorder];
[fieldEditorScroller setScrollsDynamically:YES];
[fieldEditorScroller setLineScroll:10];
[fieldEditorScroller setHorizontalLineScroll:10];
[fieldEditorScroller setVerticalLineScroll:10];
[[fieldEditorScroller contentView] setCopiesOnScroll:YES];
[fieldEditorScroller setDocumentView:fieldEditor];
// Activate the field editor.
[self addSubview:fieldEditorScroller];
[[self window] makeFirstResponder:fieldEditor];
While I can still edit the text, no scrolling happens. Perhaps I
haven't set something up correctly or a fieldEditor isn't designed
to play with a NSScrollView.
Also, while I thought I might be able to override
windowWillReturnFieldEditor:toObject:, this isn't a good option
since I need to write this code independent of the window it is
sitting on.
What I am about to try next is to create a XIB with a NSTextView
inside of a NSScrollView and bypass the fieldEditor entirely.
Well, what ended up working is creating a XIB with a NSTextView inside
of a NSScrollView and bypassing the fieldEditor entirely.
The only trick was to:
[[labelEditorController textView] setFieldEditor:YES];
so I could get the same behavior as a field editor (i.e. return ends
the editing session).
I am still surprised that I couldn't embed the field editor inside of
a NSScrollView that I created on the fly and I would like to
understand why this is not possible or what I was doing wrong.
_______________________________________________
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