w3c / selection-api

Selection API
http://w3c.github.io/selection-api/
Other
47 stars 30 forks source link

Specify when the selection collapsing happen on mouse click #90

Open saschanaz opened 7 years ago

saschanaz commented 7 years ago

Problem: The order between selection collapsing and click event is different across browsers

Demo: http://codepen.io/SaschaNaz/pen/wdeqZX

This small code listens click event, checks window.getSelection().isCollapsed, and opens a popup only when the selection is collapsed.

Howto:

click-selection

Browsers show different behavior here. In the click listener, Edge 15.16184 preview and Firefox 53 get collapsed selection, Edge 15.15063 and Chrome get non-collapsed selection (although Chrome suffers race condition and sometimes gets collapsed one).

I'm using selection check on click listener to allow users freely click anywhere to deselect text without worrying button click, but this inconsistency blocks my use case. (I expect every browser get non-collapsed selection on click listener.)