4

We use Richedit 2.0 for our script editor, which has automatic multi-level undo and redo for when you type. When we want to build our script or when the script opens, I reformat the text and send it to the rich edit control by WM_SETTEXT. This clears the undo buffer.

How can I get it so that after reformatting my script I can still press CTRL-Z and it will go back to the previous text, and previous undos before that, before I did the reformat ? I don't know how richedit saves the undos, but all it would seem to need is a way of not clearing the undo buffer when I do the WM_SETTEXT, and storing an undo point before I do that. Is this possible ?

Thanks

Shaun Southern

Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77
user3162134
  • 287
  • 1
  • 10

1 Answers1

3

Use EM_REPLACESEL and WPARAM set to TRUE to enable undo option. Example:

//select the whole range to simulate `WM_SETTEXT`
SendMessage(handle, EM_SETSEL, (WPARAM)0, (LPARAM)-1);

//replace text
SendMessage(handle, EM_REPLACESEL, TRUE, (WPARAM)L"Text");
Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77