Re: What is the preferred way to set NSTextView content from NSAttributedString?
Re: What is the preferred way to set NSTextView content from NSAttributedString?
- Subject: Re: What is the preferred way to set NSTextView content from NSAttributedString?
- From: Martin Wierschin via Cocoa-dev <email@hidden>
- Date: Mon, 3 Feb 2020 10:01:47 -0800
Yes, working through the NSTextStorage is the way to go. To replace its entire
contents you can use -replaceCharactersInRange:withAttributedString:
<https://developer.apple.com/documentation/foundation/nsmutableattributedstring/1417045-replacecharactersinrange>
with a range that encompasses all current text.
You should not need to manually call -setNeedsDisplay: on the NSTextView as was
suggested earlier. If you're working with the right NSTextStorage then its view
should observe the changes and automatically mark any redisplay as needed.
~Martin Wierschin
> On Feb 02, 2020, at 3:01 PM, Jonathan Prescott via Cocoa-dev
> <email@hidden> wrote:
>
> Looking at the documentation for NSTextView, it is highly recommended that
> you manipulate the NSTextStorage associated with the view. NSTextStorage is
> a sub-class of NSMutableAttributedtString, so you have all of those
> capabilities as well.
>
> I’m just getting into this as well for my console application related to my
> expert system interface.
>
> Jonathan
>
>> On Feb 2, 2020, at 3:37 PM, Jeff Younker <email@hidden> wrote:
>>
>> Yes, I've set needsDisplay = true in my attempts to so far. Also needsLayout
>> = true.
>>
>> The question I've got though is what is the recommended way of setting the
>> value to T2. There is no attributedString variable, just an accessor method,
>> so I've been trying a variety of insert methods.
>>
>> -jeff
>>
>> On Sun, Feb 2, 2020 at 12:19 PM Jonathan Prescott <email@hidden
>> <mailto:email@hidden>> wrote:
>> Did you tell V that it needs to re-load it’s display? There is a method on
>> NSView (from which NSTextView is derived) called “needsDisplay(sic)” which
>> sets a flag on the view so that the view will re-draw its content the next
>> display cycle. So, after you set the content to T2, you need to call
>> “V.needsDisplay()” so that the next display cycle the view gets refreshed.
>> Need to check the spelling of the method.
>>
>> Jonathan
>
> _______________________________________________
>
> 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
_______________________________________________
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