Closed rsimon closed 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.
Thank you ππ»ππ»ππ» I'll take a look tomorrow
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:
pointerup
events not contextmenu
events, thus switching the Text Annotator into normal desktop behavior.
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:
pointerup
event.keyup
event of the Shift key. (Note that selection remains editable - unless popup intervenes.)Ctrl
+A
(orCmd
+A
) is handled separately, as a single operation.pointerup
orcontextmenu
event.contextmenu
event.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.