I hope this inspires somebody to try do some stuff in Elm they’ve been needing but seemed too big / hard for them! You might, like me with this project, find out it’s in your reach - no doubt thanks to Elm
I’ve wanted to create an editor like this for a long time, the only thing holding me back was that Elm has trouble working with textareas. It seems you worked around that by simply eliminating textareas!
Anyway, I hope this doesn’t sound discouraging. Just thinking about potential features
This is amazing! Wow, I was thinking about this just today after playing a bit with Pharo. I though: “hey, Elm is all functions and type declarations, we can build a better editor than a standard text editor…”, I am so happy that you’re building this. I can’t wait to explore the code.
A simple solution might be to know how many character you are along on the line, and position the cursor that many characters along the line above or below when moving up or down - that is, how it currently works.
A solution that maintains the horizontal screen coordinates of the cursor better is going to need to know the pixel width of the text. I had to tackle that recently in order to be able to draw boxes accurately around text in SVG. Package is here, if you feel like doing something with it:
I suppose you could also somehow get bounding rects from the DOM - not sure exactly how to do that for every initial sub-string on a line though. Interestingly, when I tried this with text in SVG sometimes the bounding rect would not be correct - it would be a few pixels too small. So perhaps this kind of approach is not even worth trying.
Either way, getting text widths is a bit of a PITA.
A third way, and something I am interested in exploring, would be to parse the OpenType font into an equivalent set of data structures in Elm - that is codegen them to .elm files. Then implement the width calculations in pure Elm. This becomes worth doing in 0.19, because dead code elimination will cut out any fonts that you don’t use, so a package with a decent set of common fonts could be published and it would not bloat your code.