Implementing Code Highlighting

566 Views Asked by At

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)

3

There are 3 best solutions below

0
On BEST ANSWER

Scintilla is used in a lot of different editors. Notepad++ is one of them.

Here is a .Net wrapper: http://scintillanet.codeplex.com/

enter image description here

0
On

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:

0
On

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