• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: fieldEditor not scrolling to keep insertion point / indicator visible
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 14:42:30 -0500


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.

Any other suggestions or comments?




_______________________________________________

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


  • Follow-Ups:
    • Re: fieldEditor not scrolling to keep insertion point / indicator visible
      • From: Eric Gorr <email@hidden>
References: 
 >fieldEditor not scrolling to keep insertion point / indicator visible (From: Eric Gorr <email@hidden>)

  • Prev by Date: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
  • Next by Date: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
  • Previous by thread: fieldEditor not scrolling to keep insertion point / indicator visible
  • Next by thread: Re: fieldEditor not scrolling to keep insertion point / indicator visible
  • Index(es):
    • Date
    • Thread