实现代码高亮
我有一种面向堆栈的编程语言,我需要为其编写一个非常简单的编辑器,并具有代码突出显示功能。最好使用 RichTextBox
执行此操作,
我见过许多突出显示示例和演示的代码,几乎所有代码都需要刷新整个 RichTextBox
OnTextChanged
。这适用于较小的代码文件,甚至对于稍大的代码文件,如果滚动条正确地重新定位,但文件越大,尝试编辑时的滞后就越大。
必须有更好的方法。显然,Visual Studio 做得完美无缺...
那么,我应该使用什么方法呢?
(伪代码甚至只是一般概念布局都可以作为答案)
I have a stack oriented programming language that I need to write a very simple editor for, with code highlighting. It would be preferable to do such with a RichTextBox
I have seen many code highlighting samples and demos, and nearly all of them require the entire RichTextBox
to be refreshed OnTextChanged
. This works for smaller code files, and even with slightly larger ones, if the scrollbar is correctly re-positioned, but the bigger the file gets, the greater the lag when trying to edit.
There's got to be a better way. Obviously, Visual Studio does it flawlessly...
So, what method should I use?
(Pseudocode or even just a general concept layout is fine for an answer)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我强烈建议您使用开源的 ICSharpCode.TextEditor。这是一个非常丰富的文本编辑器,支持可定制的语法突出显示甚至智能感知。其他功能包括行号、错误突出显示、错误提示、代码块折叠等。
使用它的应用程序示例包括:
I strongly recommend you to use the open-source ICSharpCode.TextEditor. This is a very rich text editor with support for customizable syntax highlighting and even intellisense. Among other features like line-numbers, error-highlighting, error-hinting, code-block-collapse and etc.
Examples of applications that use it are:
Scintilla 用于很多很多不同的编辑器。 Notepad++就是其中之一。
这是一个 .Net 包装器: http://scintillanet.codeplex.com/
Scintilla is used in a lot of different editors. Notepad++ is one of them.
Here is a .Net wrapper: http://scintillanet.codeplex.com/
不确定你是否真的想编写自己的,我使用了 AvalonEdit,来自 SharpDevelop 类似的东西,效果非常好。虽然它是 WPF,但你没有说你使用的是什么 UI 技术。您甚至可以在具有许可证的商业软件中使用它。
国杰
Not sure if you really want to write your own, I used AvalonEdit, the editor from SharpDevelop for something similar, works pretty nice. It's WPF though, you didn;t say what UI technology you're on. You can even use it in commercial software with the license.
GJ