Demo project: https://github.com/BalazsJako/ColorTextEditorDemo
This is my attempt to write a relatively simple widget which provides source code editing functionality with basic syntax highlighting.
While it relies on Omar Cornut's https://github.com/ocornut/imgui, it does not follow the “pure” one widget - one function approach. Since the editor has to maintain a relatively complex internal state, it did not seem to be practical to try and enforce fully immediate mode.
The code is work in progress, please report if you find any issues.
Main features
- approximates typical code editor look and feel (essential mouse/keyboard commands work - I mean, the commands I normally use :))
- undo/redo support
- extensible, multiple language syntax support
- identifier declarations: a small piece of text associated with an identifier. The editor displays it in a tooltip when the mouse cursor is hovered over the identifier
- error markers: the user can specify a list of error messages together the line of occurence, the editor will highligh the lines with red backround and display error message in a tooltip when the mouse cursor is hovered over the line
- supports large files: there is no explicit limit set on file size or number of lines, performance is not affected when large files are loaded (except syntax coloring, see below)
- color palette support: you can switch between different color palettes, or even define your own
- supports both fixed and variable-width fonts
Known issues
- syntax highligthing is based on std::regex, which is diasppointingly slow. Because of that, the highlighting process is amortized between multiple frames. Hand-written colorizers and/or a lexical scanner might help resolve this problem.
- 8 bit character only, no Unicode or Utf support (yet)
- there's no find/replace support
Don't forget to post your screenshots if you use this little piece of software in order to keep me us motivated. :)
Contributing
Pull requests are welcome, feel free to contribute if you have implemented something which might be useful for the general audience of this little piece of software. Apparently, it became kind of a community project now. :)
Whem contributing, please follow the following guidelines. I will keep it updated as we bump into something which worth doing better.
- Try to follow the same coding and naming conventions you find in the source already. I know that everyone has its own preference/taste in coding, but please keep the source consistent in style.
- Please submit to the ‘dev’ branch first for testing, and it will be merged to ‘main’ if it seems to work fine. I would like try keep ‘master’ in a good working condition, as more and more people are using it.
- Please send your submissions in small, well defined requests, i. e. do not accumulate many unrelated changes in one large pull request. Keep your submissions as small as possible, it will make everyone's life easier.
- Avoid using ImGui internal since it would make the source fragile against internal changes in ImGui.
Thank you. :)