A tiny text editor

Mininotes in action

See the project here!

The main goal of mininotes for me was to learn about text editing, and how to handle characters. I've managed to do this, and luckily for rust there's a few libraries to help with it. The hardest part here is ensuring graphemes (what is expected to be 1 character visually) work correctly, while all string representations deal with either characters (codepoints) or bytes.

Cursor navigation

The implementation of cursor navigation is quite naive. When moving left or right, it's moved over by one grapheme, and recalculates where it is on the line. Recalculating works by simply looping over all characters on the line until the cursor, and calculating their widths.

Then when moving the cursor vertically, this is used (again with linear search) to place the cursor on the correct spot in the line.

This works fine, unless you are editing a large minified javascript file. vim seems to handle this fine, helix does have some issues with it at the time of writing.

I suspect a much more efficient implementation would handle caching of this per glyph, and then binary search it instead.

UI layout

The UI layout is simple. You start with a square. You can fill one side (top, bottom, left or right) of the square with some UI, then repeat for the remaining square.

This works quite intuitively for larger elements, but does not allow nearly as much flexibility as other layout mechanisms. It works fine for mininotes.