I’ve been fashing around trying to find a way to enable Undo in a TextArea when I run an extensive search and replace on the entire text (think thousands of replacements). Selecting all and replacing the selected text doesn’t activate the Apple Undo system. I can’t really see how to do this with NSUndoManagerMBS.
Anyone have any ideas?
How are you doing the global replace ?
textArea.text = regex.replaceAll(textArea.text)
When you replace in the Text property, the system has no idea of what you did, and cannot undo.
You could change the menu handler for undo in TextArea.getFocus to another menu handler, so you handle the undo, and reinstate the normal menu handler in TextArea lostfocus.
Save the original Text in a variable before the replace, so you can reload it in case the user wants to undo.
I thought of that. One problemthen I have to handle all the text undos. %^(
Being a lazy person, I’d like to find a way to use Apple’s Undo system so the user can undo their rampant misspellings without me having to think about that and let me change 20,000 line-endings at their request with the possibility of reverting them.
I believe you can do a paste with RemoteControlMBS (Christian ?) by simulating Cmd-V. Then what you do is load the replaced text into the clipboard, the simulate Cmd-A, then Cmd-V, and your text is replaced with the system being aware of it.
I would suggest saving the content of the clipboard and restoring it afterward to avoid the user being confused by a clipboard which changed on him.
That’s sounds possible, Michel. Thanks. I’ll take a look at it.