In JavaScript range selection is it possible to prevent selection of a partial node?
For example:
"The enormous cat sat on the very small rug."
A user might select "cat" and more often than not, their mouse selection is not that precise and includes the visible space either side as well, and thus the selection range nearly always includes "enormous" and "sat" which we do not want.
Each span contains a single word. The visible space in between words could be true whitespace inside a span tag, spans stacked with line-breaks, it could be padding, it also could be css word-space, or even a non-breaking space. Whichever way if the user's selection strays into another node unintentionally, the default is of course is to return the node as part of the selection.
How can this be avoided?
Any pointers gladly accepted.
Thank you kindly.
Example code:
<span id="a1">The </span>
<span id="a2">enormous</span>
<span id="a3"> cat </span><span id="a4">sat</span>
<span id="a5"> on </span><span id="a6" style="padding-right: 2px;">the</span>
<span id="a7">very </span><span id="a8">small </span><span id="a9">rug</span><span id="a10">. </span>