Getting the current text container or text view from a layout manager
Getting the current text container or text view from a layout manager
- Subject: Getting the current text container or text view from a layout manager
- From: Keith Blount <email@hidden>
- Date: Sat, 26 Jan 2008 09:05:53 -0800 (PST)
Hi,
I have a page layout view a little like the "Wrap to Page" mode in TextEdit, and I would like to display the current page number in a bar at the bottom of the window. However, I cannot seem to find a way of getting the currently edited page. I have registered for the NSTextViewDidChangeSelectionNotification and upon receiving that notification I am trying to obtain the current text view or text container, the idea being that this would then give me the page number by doing something like:
pageNo = [[layoutManager textContainers] indexOfObject:currentTextContainer] + 1;
I cannot find a way of getting the current text container or text view, though - i.e. the one that contains the insertion point.
If there is a selection, I can get the current text view or container easily enough using NSLayoutManager's -textViewForBeginningOfSelection method. However, if there is no text selected, this method returns nil, so it completely fails while the user is editing text or typing.
The Text System User Interface Programming Guide (https://developer.apple.com/documentation/Cocoa/Conceptual/TextUILayer/Tasks/MultipleViews.html) states that, "With multiple NSTextViews, only one is the first responder at any time", which seems obvious enough. From this I expected that NSWindow's -firstResponder method would return the text view with the focus. It doesn't. In my -textDidChangeSelection: method, I tried calling [[pageView window] firstResponder] to get the current text view. But this always returns the first text view (i.e. the text view returned by NSLayoutManager's -firstTextView method).
It thus seems that there is no way to get the text view or text container that is currently being edited by the user or that contains the blinking insertion caret, but that can't be right so I must be missing obvious.
Does anybody have any ideas about how to go about this, or about what I might be missing?
Many thanks in advance,
Keith
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
_______________________________________________
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