JSFiddle - React, Tailwind, and code Playground
HTML
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex eos, provident architecto aliquid facilis soluta sequi nam consequuntur veritatis! Inventore hic, optio quo dignissimos veritatis saepe ut laborum, voluptas modi.</div>
JavaScript
var throttle = false;
var sel = window.getSelection();
var selStart = 0;
var selEnd = 0;
document.querySelector('div').addEventListener('click', function (evt) {
if (!throttle && evt.detail === 2) {
selStart = sel.anchorOffset;
selEnd = sel.focusOffset;
}
if (!throttle && evt.detail === 3) {
var node = this.firstChild;
sel.removeAllRanges();
throttle = true;
var range = document.createRange();
range.setStart(node, selStart);
range.setEnd(node, selEnd)
sel.removeAllRanges();
sel.addRange(range);
}
});