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

我与影子孤独终老i 提交于 2019-12-06 09:48:19

问题


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?


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/4138981/temporaily-disabling-the-c-sharp-rich-edit-undo-buffer-while-performing-syntax-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!