Re: NSTextView scrolls to top on Save
Re: NSTextView scrolls to top on Save
- Subject: Re: NSTextView scrolls to top on Save
- From: Andy Lee <email@hidden>
- Date: Sun, 19 Dec 2010 21:44:24 -0500
On Dec 19, 2010, at 8:04 PM, Kyle Sluder wrote:
> On Sun, Dec 19, 2010 at 1:20 PM, Andy Lee <email@hidden> wrote:
>> I can understand why Apple wouldn't use a bindings-based solution for this example, since bindings is an advanced topic unto itself, but I think using an NSTextStorage would be appropriate given the context. Unless someone spots a fatal flaw, I'll submit it as a doc suggestion.
>
> The reason they didn't use bindings here is because it's not
> appropriate for hooking up an NSTextStorage to an NSTextView.
To be clear, my original version, with bindings, used an NSAttributedString (actually an NSMutableAttributedString, which may have confused matters; I should have used NSAttributedString for the ivar).
I introduced the NSTextStorage not because I expected it to work with bindings, but because I thought it was a design improvement to Apple's sample code.
> Bindings (really, KVO) can't deal with mutable value types. In the
> world of KVO, all changes mean that the actual object identity has
> changed, not merely the value it contains.
Indeed, the V in KVO refers to the object's identity and not its contents. But if I go back to the bindings approach and turn on "Continuously Updates Value", I can see from NSLogs that the setter for the ivar gets called when I make any change to the text, even though the id of the ivar has not changed, only its content. So NSTextView's attributedString binding seems designed to work the way I would want...
...*except* for that bit about scrolling to the top when I do a Save. And I just discovered this only happens if the text view had first responder at the time of the Save. If I select something else in the window and *then* do a Save, the text view stays right where it was. I think this must be a bug. Unless someone can explain why it isn't, I'll file a Radar.
--Andy
_______________________________________________
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