mathlive icon indicating copy to clipboard operation
mathlive copied to clipboard

Unique atoms are not deleted properly when part of a range

Open jgranick opened this issue 9 months ago • 2 comments

Issue

Selecting editor text and deleting is broken if you select the opening portion of a group (such as \sqrt).

How to reproduce

Use shift+arrow to highlight. Press delete.

Demonstration

Using backspace to remove one character at a time works properly:

https://github.com/user-attachments/assets/cc6d78b4-750b-441a-af24-5a6b149a5d6b

Selecting a range and deleting is broken and leaves the special atom behind:

https://github.com/user-attachments/assets/4f3df805-2442-4dab-884e-c2988cb4fd8d

Additional details

editor-model onDelete has code to handle special cases for square root, box, genfrac and other unique atoms. However, it is not called when a range is being removed.

jgranick avatar Apr 08 '25 14:04 jgranick

Example fix

Here is an example which resolves the above specific case by using deleteBackward in a loop instead of maintaining separate range delete logic

https://github.com/jgranick/mathlive/commit/cdddd7aaa23055a3029a5f6a25723ea41fca67ae

jgranick avatar Apr 08 '25 14:04 jgranick

editor-model onDelete has code to handle special cases for square root, box, genfrac and other unique atoms. However, it is not called when a range is being removed.

As a result, there are edge cases which are missing, for example:

I also see that the square root symbol (\sqrt{}) incorrectly inherits the default caret color before the <math-field> gains focus. This suggests that before editing the <math-field>, the visual caret style is already applied to the square root, which is undesirable.

andrea78 avatar Apr 09 '25 03:04 andrea78