I’ve been using the TextEditor for years, for things it wasn’t meant to, such as displaying megabyte-size text files, so I’m happy to see that the CodeEditorComponent does this much faster.
I replaced some TextEditor components with CodeEditorComponents, inadvertently using the same proportinally-spaced font, and this actually works quite well for display, as long as I don’t try to highlight or edit the text.
It seems the text rendering code already works sensibly with proportionally spaced fonts, and the only things that would need change are the highlightning x positions in CodeEditorComponent::CodeEditorLine::draw and the positions calculated in getCharacterBounds and getPositionAt. Ideally, the caret positioning logic should remember the x offset rather than the column when using up/down arrows, but that’s a minor thing.
These changes won’t cause a noticeable slowdown as they are generally only used a few times per refresh, and only for text lines actually shown.
I want this because I’d like to replace the TextEditor with the much faster CodeEditorComponent in my PILS programming system. When I work with code analysis (for the time being, it’s Delphi -> C#), I often happen to dump megabyte-sized indented syntax trees which is painfully slow with the former. I’m used to working with proportionally spaced fonts and find the monospaced fonts tiring to read, plus proportinal fonts are more compact and show more text in the same area.
By the way I had great trouble with crashes from premature deletion of the CodeDocument because, for obscure reasons related to the Component/refcount/weak-reference issue, PILS queues componens for deletion in the main loop rather than deleting them immediately. I ended up with a quite horrible hack replacing the supplied CodeDocument with another that gets queued for deletion by the destructor of a CodeEditorComponent. Since your :twisted: C++ aesthetics require me to pull such nasties, perhaps you could consider making the CodeDocument object and the lexer refcounted?