Question

I already have a pretty decent syntax highlighter in my Rich Edit control but I have one final problem before it is fully useful: Whenever I run the syntax coloring it records those coloring actions in the undo buffer, which I do not really want. Is there any way to temporarily disable recording undo actions so that after a coloring the user can press undo and it will just undo the user's own actions and not the automated syntax highlighter?

I don't think I have the time to implement the Scintilla.NET editor just to get around this problem though. Any suggestions?

Was it helpful?

Solution

You will have to handle undo/redo yourself instead of relying on RTB, which means hooking into the keyboard events to listen for CTRL+Z, etc.

You can see how this author from codeproject did it for a similar RTB-overridden syntax highlighting editor: http://www.codeproject.com/KB/edit/SyntaxHighlighting.aspx

OTHER TIPS

Almost as @Karl Edwall says above, but not quite: Use EM_GETOLEINTERFACE to obtain IRichEditOle interface and query it for IID_ITextDocument.

Once you get that, use (instead of Freeze/Unfreeze from the other answer) the Undo() method:

  • Undo(tomSuspend,NULL); to suspend undo temporarily
  • Undo(tomResume,NULL); to resume it again

(See http://support.microsoft.com/kb/199852.) It requires RichEdit 3.0, but that’s shipping since Windows XP SP1.

Well from C++ what you would do is use the IRichEditOle COM interface e.g. to get to the ITextDocument TOM interface and call Freeze and Unfreeze to prevent your changes to go into the Undo bufer. Maybe this article http://www.codeproject.com/KB/edit/richtextboxplus.aspx can be of some help in doing that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top