Trying to figure out how to properly detect if text is unselected.
In Firefox you can highlight text, click inside and it totally deselects.
In Chrome/Chromium if you click inside highlighted text that's still counted as selected until one more click (even though the visual highlight is gone).
How do we work around this?
JS / Jquery Code:
function getSelected()
{
var return_text;
if (window.getSelection)
{
return_text = window.getSelection();
}
else if (document.getSelection)
{
return_text = document.getSelection();
}
return return_text;
}
$(document).on('click', "div", function(e)
{
var selection = getSelected();
var selectedText = selection.toString();
console.log(selectedText);
});
HTML for testing:
<div>
This is some text. Open your F12 console and select some text to test me<br />
<br />
In Chromium, the selected text stays until you click twice even though it is visually unselected on the first click. In Firefox, it clears properly on one click.<br />
<br />
Why is Chromium doing this? It's causing really annoying behaviour.
</div>
Example: https://jsfiddle.net/7sf35c4j/
From what I can see, this makes it basically impossible in Chrome/Chromium to accurately know when something is deselected???