In my opinion, using layoutManager:didCompleteLayoutForTextContainer:atEnd is 
fraught with danger and should be avoided. Most of the time, it does not not 
provide truly useful information and you cannot rely on layout being complete 
even if the flag is YES.

If you open a new page-wrapped document in Text Edit and type returns until a 
second page is added, then press delete, the added page is not removed. Type 
any character, and the page is removed. That is because the method in question 
did not fire in response to the delete key.

I think it is far safer and more reliable to count the number of text 
containers by calling a method after every event that could affect layout, 
using the performSelector:withObject:afterDelay: wrapper to insure that layout 
is complete. Depending on your needs, it might be sufficient to override 
NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:.
 


On May 9, 2011, at 3:36 PM, Philip Dow wrote:

> I just submitted the following bug report and wanted to post it here as well 
> to see if anyone had a recommended workaround.
> 
> NSLayoutManager layoutManager:didCompleteLayoutForTextContainer:atEnd 
> callback is never called with atEnd flag set to YES if last character of text 
> is NSFormFeedCharacter.
> 
> Summary:
> The NSLayoutManager callback 
> layoutManager:didCompleteLayoutForTextContainer:atEnd: is called as layout is 
> completed for each text container in a multipage view. The atEnd flag is set 
> to YES when the last text container is layed out. This method is never called 
> with the atEnd flag set to YES if the last character in the text is the page 
> break (NSFormFeedCharacter) control character.
> 
> This is verifiable on Mac OS 10.6.7 through testing with TextEdit source code 
> that is included in the Xcode distro.
> 
> Steps to Reproduce:
> Create a multipage text document in TextEdit with text wrapping enabled. Add 
> a page break as the last character in the document and save the document. 
> Next time the document is opened, the layout manager callback never occurs 
> with the atEnd flag set to YES.
> 
> Expected Results:
> When the last container is layed out, the atEnd flag should be set to YES.
> 
> Actual Results:
> The didCompleteLayoutForTextContainer is correctly called a number of times 
> for each text container with the atEnd flag set to NO, but it is never 
> finally called with the atEnd flag set to YES for the last text container.
> 
> ~
> 
> I'm hoping someone might have some insight into this or a possible 
> workaround. I have some code that depends on a correct count of the number of 
> layed out pages and that count is determined when layout is completed, as 
> indicated by the atEnd flag set to YES.
> 
> ~Phil_______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/rosscarterdev%40me.com
> 
> This email sent to rosscarter...@me.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to