Skip navigation.
 
mlPasteboard inconsistencies
FROM : Randall Meadows
DATE : Fri Apr 18 20:07:58 2008

I'm doing some manipulation of selected text and having some 
inconsistencies, apparently based on what the *contents* of the text 
is.  I'm very confused about this, hopefully someone can set me 
straight.

I'm using writeSelectionToPasteboard:types: to get the current text 
selection, using a custom pasteboard ([NSPasteboard 
pasteboardWithUniqueName]) and pass an array containing only 
NSStringPboardType for "types".

That all works, I get the text using [pb 
stringForType:NSStringPboardType], and I perform my manipulation on 
it; I can see the results of it, and it's exactly what I expect.  The 
problem surfaces when I try to replace the selection with my new text.

I put the new text onto my custom clipboard using [pb 
setString:newText forType:NSStringPboardType], and then replace the 
selected text with [view readSelectionFromPasteboard:pb].  Now, for a 
simple string like "asdf", this works just fine.  The problem occurs 
when the new text contains control characters, like a carriage return 
or a tab character.  In that case, the text is not replaced with the 
new text I've just placed on my custom clipboard, but rather with the 
contents of the general pasteboard (like what I see when I select Show 
Clipboard from Finder's Edit menu).

Immediately after the setString call, I can 'po [pb 
stringForType:NSStringPboardType]', and I see that my new text is 
indeed there.  Why come then is it taking the text from a totally 
different pasteboard than what I specified, and even then only 
*sometimes*, depending on whether there are control characters in the 
text?


TIA!
randy

Related mailsAuthorDate
No related mails found.