开发者

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

开发者 https://www.devze.com 2023-01-24 11:35 出处:网络
I already have a pretty decent syntax highlighter in my Rich Edit control but I have one final problem before it is fully useful:

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 sy开发者_高级运维ntax 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消