Text editing notification for size changed
-
I'm looking to do something somewhat like the Sketch example, where
there's an NSTextView. As the user types, there should be word wrap.
This will cause the NSTextView to grow. I need to get its new bounds
when this happens.
I don't see any notifications that tell me when it happens. Sure,
there's NSTextDidChangeNotification, but this is sent after every
character is typed. And based on the Sketch example, you've then got
to go through a lot of stuff to measure the new height. I'm really
not looking to performance if I have to do this each character typed.
Is there a better way?
David Dunham http://www.pensee.com/dunham/
Imagination is more important than knowledge. -- Albert Einstein -
On Oct 5, 2005, at 11:03 PM, David Dunham wrote:
> I'm looking to do something somewhat like the Sketch example, where
> there's an NSTextView. As the user types, there should be word
> wrap. This will cause the NSTextView to grow. I need to get its new
> bounds when this happens.
>
> I don't see any notifications that tell me when it happens. Sure,
> there's NSTextDidChangeNotification, but this is sent after every
> character is typed. And based on the Sketch example, you've then
> got to go through a lot of stuff to measure the new height. I'm
> really not looking to performance if I have to do this each
> character typed. Is there a better way?
>
Hi David,
Look at NSView's -setPostsFrameChangedNotifications: method. You can
turn this on for your NSTextView and then observe the notifications
to see when it grows.
Hope this helps,
-- Greg -
On 5 Oct 2005, at 23:11, Greg Titus wrote:
> Look at NSView's -setPostsFrameChangedNotifications: method. You
> can turn this on for your NSTextView and then observe the
> notifications to see when it grows.
I was originally getting this only when I typed a return (and now I'm
not getting it at all). I must be setting up the NSTextView wrong.
Some excerpts:
[tv setHorizontallyResizable: NO];
[tv setVerticallyResizable: YES];
[tc setWidthTracksTextView:NO];
[[editor textContainer] setContainerSize: fBounds.size];
David Dunham A Sharp, LLC
Voice/Fax: 206 783 7404 http://a-sharp.com
"People seem to misinterpret complexity as sophistication" -- Niklaus
Wirth -
On Oct 6, 2005, at 8:21 AM, David Dunham wrote:
> On 5 Oct 2005, at 23:11, Greg Titus wrote:
>
>
>> Look at NSView's -setPostsFrameChangedNotifications: method. You
>> can turn this on for your NSTextView and then observe the
>> notifications to see when it grows.
>>
>
> I was originally getting this only when I typed a return (and now
> I'm not getting it at all). I must be setting up the NSTextView
> wrong. Some excerpts:
>
> [tv setHorizontallyResizable: NO];
> [tv setVerticallyResizable: YES];
> [tc setWidthTracksTextView:NO];
>
> [[editor textContainer] setContainerSize: fBounds.size];
That last line is telling the text container that it is only as tall
as the view (I assume that's what fBounds is). You need to be telling
the text container that it can be infinite height so that the text
grows instead of reaching the end of the container and overflowing to
the next container (which means overflowing to nowhere since you
probably only have a single container).
Check here for what your code should look like (Setting Up the Text
View):
http://developer.apple.com/documentation/Cocoa/Conceptual/TextUILayer/
Tasks/TextInScrollView.html#//apple_ref/doc/uid/20000938-117804
Hope this helps,
- Greg


