Search code examples
c#winformsrichtextboxrich-text-editorrichedit

Temporaily disabling the C# Rich Edit undo buffer while performing syntax highlighting


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?


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