I would like to capture a string being pasted into a control and apply some custom formatting to the string before being pasted.
How is this possible?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Override
paste:in your view/control (paste: is part of theUIResponderStandardEditActionsinformal protocol). At the simplest, you’d do this:This is assuming you don’t need to do something terribly fancy with the string (like inserting animated smileys or something), in which case you shouldn’t call
superbut do the insertion yourself (if you are doing this on aUITextViewyou can use theselectedRangeproperty to do the insertion properly).EDIT: To get data from a
NSPasteBoardyou should use–stringForType:or one of several other data access methods. You might have to validate the string/data to make sure it’s something that can be pasted.You probably shouldn’t call
superbut useif you’re doing this on a NSTextView. If you’re working with another class you have to find out what’s appropriate in that context.