stefnotch / aftermath-editor

A WYSIWYG mathematics editor that understands your formulas!
https://stefnotch.github.io/aftermath-editor
MIT License
14 stars 0 forks source link

Experiment: Alternative Web Input Design #56

Open stefnotch opened 1 year ago

stefnotch commented 1 year ago

One alternative to the current editing model would be to go all in on the invisible textarea. Then we'd naturally handle IME input and such.

  1. The invisible textarea contains all the text on the current row. Fractions and co are replaced with some escape character(s). [1]
  2. Arrow Key Movement first happens in the textarea, and then we query where we are.
  3. Optional: We can change the "symbols" design to "strings". Heck, we could go all in on the strings by doing the [1] thing.
  4. Whenever we switch to a different row, the textarea content gets replaced with the content from that row.

[1]. For the escape character, we could pick one character from the https://en.wikipedia.org/wiki/Private_Use_Areas. And then, we have an internal Map<Offset, InputElement>, which maps from such a character+its position to the actual element at that position. We could also always use two characters, to support "deleting -> jump into fraction" and "fully deleting -> delete entire fraction"

An advanced version would be an invisible "contenteditable" area, where the characters are carefully placed to align with the rendered characters. Wrapping every character in a span, and then setting the bounds of the span might work.

stefnotch commented 1 year ago

Things that would be automatically handled:

Things that have to be manually implemented:

Things that I don't need

stefnotch commented 1 year ago

Sooner or later we might get better APIs like the https://w3c.github.io/edit-context/