recogito / text-annotator-js

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

Revised Selection Behavior #151

Closed rsimon closed 1 month ago

rsimon commented 1 month ago

In this PR

This PR revises the selection behavior fundamentally. Instead of creating an annotation immediately, the SelectionHandler now waits until the (native browser text-)selection is 'complete'. Because there is not actually a 'complete' event, there are different approaches, depending on platform and interaction mode:

Note: in all cases, the selection remains editable after "completion", either by using Shift+Arrow keys (desktop) or by dragging the handlebars (on mobile/touch).

React Popup

I also modified the React TextAnnotatorPopup with the following behaviors:

Warning: mobile mode is detected through navigator.userAgent. It appears that Firefox currently does not include sufficient information to determine whether it is running on iOS. Therefore, FF/iOS currently behaves like on the desktop, which also means it will lose the selection handlebars as soon as the <TextAnnotatorPopup> opens.

rsimon commented 1 month ago

Hi @oleksandr-danylchenko,

I'm about to merge this into main soon. But wanted to give you a heads-up and chance to look over the changes. I think this should work well on all platforms. But do let me know if you have any doubts, or find something that I missed.

I so far tested this on FF + Chrome (Mac, iPad, Android) and will do another round of testing on FF/Chrome/Edge on Linux tomorrow, with a hybrid desktop/touch computer.

oleksandr-danylchenko commented 1 month ago

Thank you πŸ™ŒπŸ»πŸ™ŒπŸ»πŸ™ŒπŸ» I'll take a look tomorrow

rsimon commented 1 month ago

Update: I added a few more tweaks. Bad news first: I could not find a perfect solution for CTRL/CMD-A, unfortunately. (There's a timeout involved, which might presumably lead to timing issues if large texts are involved. Not sure if CTRL-A on large texts is such a big use case though?)

Other than that, however, everything seems to work as it should!

I tested with the standard test page from packages/text-annotator-react (which includes the dummy popup with a text input field). On the following devices/browsers:

* The hybrid Ubuntu notebook had some issues when used with touch. But I think none of these are dealbreakers, and tolerable: