arnog / mathlive

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

Selection erased despite beforeinput being cancelled #2397

Closed gunnarmein-ts closed 3 weeks ago

gunnarmein-ts commented 3 weeks ago

Description

I am cancelling the "beforeinput" event to effectively switch the virtual and physical keyboard off. This works for most scenarios. However, when there is an active selection, that selection is deleted upon pressing a physical key (virtual works as expected).

Steps to Reproduce

  1. load the attached test.html test.html.zip

  2. inspect source to see that beforeinput has preventDefault().

  3. double-click on the "sin" in the field to select it

  4. press a virtual key - all good, nothing happens

  5. press a physical key - the selection is gone

Actual Behavior

the selected text is deleted

Expected Behavior

the selected text should remain, as with the virtual keys

Environment

Mathlive 0.100.0

gunnarmein-ts commented 3 weeks ago

I am currently working around this by also trapping keydown, arguably that's good enough, but I wanted you to know about the behavior.