sakurashinken
sakurashinken

Reputation: 4080

paste of nsmutableattributed string to public pasteboard loses attributes in pages

I am creating a mac standalone service that puts attributed strings on a pasteboard. When the data is accessed by pages, the string loses its attributes. I am using the following code to paste the string, with the NSReturnTypes value set to NSStringPboardType.

    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Yay, I'm a string"];

[str beginEditing];

[str addAttribute:NSUnderlineStyleAttributeName
               value:[NSNumber numberWithInt:NSUnderlineByWord]
               range:NSMakeRange(0,str.length)];

[str endEditing];

[pboard clearContents];
[pboard writeObjects:[NSArray arrayWithObject:str]];

Non iWork applications such as notes and mail can process the attributes just fine but pages insists on dropping them. How can I create pasteboard data that is processable by pages, keynote, and numbers?

UPDATE: Apparantly iWork applies the current style up to the first newline on text that is pasted over already existing text in the document. I am assuming that paragraph styles are behind this, but would appreciate any help here.

UPDATE2: It appears to be a bug in how pages accepts data from the clipboard.

Upvotes: 0

Views: 121

Answers (2)

CRD
CRD

Reputation: 53000

Nobody has offered you anything yet, so here is an approach not an answer as such:

I am assuming that paragraph styles are behind this, but would appreciate any help here.

Don't assume, test.

Write a simple app which allows you to examine what is on the clipboard. Then open TextEdit & Pages and copy & paste things both in and between the apps. See what is on the clipboard. Pages does a certain amount of "match style" pasting even when "Paste and Match Style" is not selected.

Note of course that this issue is not restricted to your app, as you'll see when copying from TextEdit (or Word et al) into Pages. Your aim appears to be to replicate Pages to Pages copy & paste, it may or may not be possible.

Addendum

If you need help with viewing the clipboard Apple have sample code to do it, ClipboardViewer. Just compare your underlined word when copied from TextEdit and Pages. Quite a few differences including iWork specific data types.

HTH

Upvotes: 1

sakurashinken
sakurashinken

Reputation: 4080

It appears to be a bug in Pages, or intended behavior. https://discussions.apple.com/message/30971829?ac_cid=op123456#30971829

Upvotes: 0

Related Questions