arnog / mathlive

A web component for easy math input
https://cortexjs.io/mathlive
MIT License
1.56k stars 277 forks source link

PlusMinus retains some kind of state #2368

Closed gunnarmein-ts closed 3 months ago

gunnarmein-ts commented 4 months ago

Description

After deleting a plusminus sign with backspace, some kind of state is retained that makes the next minus key back into a plusminus

Steps to Reproduce

  1. Open the Mathlive demo page, delete the current contents
  2. type "+-". observe the \pm.
  3. hit backspace (delete on mac)
  4. type "-"

Actual Behavior

\pm is inserted again

Expected Behavior

"-" should be inserted

Environment

Mathlive 0.98.6 on demo page macOs chrome and Safari, current versions.

arnog commented 4 months ago

This is not an issue specific to PlusMinus, but goes to how inline shortcuts are handled. I understand this interaction may be unexpected, but it's unclear how to improve it.

Currently, a buffer keeps tracks of the keys that have been typed and on each new key considers if an inline shortcut is applicable. That buffer gets resets in some cases, for example if the selection is change or if the cursor is moved. However, on backspace the buffer is not reset, but instead the last entry in the buffer is removed. This allows a mistype such as sinj to be corrected by typing BACKSPACE and h. If the buffer were reset on backspace, in order to correct this mistype you would need to type backspace twice, then retype sinh.

gunnarmein-ts commented 4 months ago

Every shortcut conversion could snapshot the state of the mathfield before conversion and set a one-keystroke-trap for backspace, and if backspace is pressed, it could restore that snapshot before processing the backspace.