recogito / text-annotator-js

A JavaScript library for text annotation.
BSD 3-Clause "New" or "Revised" License
22 stars 7 forks source link

The annotation selection cannot be discarded once at least a single character got selected ⚠️ #139

Closed oleksandr-danylchenko closed 1 month ago

oleksandr-danylchenko commented 3 months ago

Issue

Once you start selecting the text either by mouse or keyboard, you cannot cancel it by collapsing the selection range.

Mouse

https://github.com/user-attachments/assets/8ee72e2d-eadc-4bcb-9668-620713355ac7

The mouse selection dispatches the selectstart event only once and after that, only the selectionchange until you release. During that time you're stuck in "at least 1-char selection limbo", and the rendered highlight won't get dismissed

Keyboard

https://github.com/user-attachments/assets/71286df9-e1cb-4fb1-b139-6ff14c7b885b

The keyboard selection dispatches the distinct selectstart event each time the previous selection range becomes collapsed. So each time you switch the selection direction, a new leftover annotation gets saved. Which is even more annoying than the mouse-limbo 💀

Suggested Changes

We should track the moment when the previously populated selection range collapses. That should signify the selection cancellation. Then, such leftover annotations can be deleted.