Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing Code Highlighting

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)

like image 612
Entity Avatar asked Feb 20 '26 07:02

Entity


2 Answers

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:

  • SharpDevelop
  • LINQPad
like image 145
André Pena Avatar answered Feb 21 '26 20:02

André Pena


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

like image 24
jgauffin Avatar answered Feb 21 '26 22:02

jgauffin