toggle-selection
toggle-selection copied to clipboard
Not working if the selected text is in disabled textarea in FF
If user selects text in disabled textarea (and probably input as well) in Firefox (104.0.2 in my case), this function doesn't deselect it.
It is pretty nasty in combination with this https://github.com/sudodoki/copy-to-clipboard
oh my, does document.execCommand works on its own in this case?
Yes, this works. But if there is disabled textarea with text selected somewhere in the page, the selected text gets copied instead of the text that is sent to copy-to-clipboard.
Unfortunatelly, as it seems, enabling the textarea before trying to apply toggle-selection and then disabling again it doesn't solve the problem. Seems that selected text during 'disabled' mode doesn't make the blur method deselect it later even if it is enabled at that moment (didn't test this that much though).
yeah I don't have FF either to test it out. Does it still work for your use case in other browsers?
I had to install FF to work on this as well :-) In Chrome it works as expected. Didn't test other browsers.
I see, well my guess would be it's either:
selection.rangeCountreturning falsy value in this case :thinking: (https://github.com/sudodoki/toggle-selection/blob/gh-pages/index.js#L4)active.blurthrowing an exception (https://github.com/sudodoki/toggle-selection/blob/gh-pages/index.js#L17)
- I don't think
selection.rangeCounthas anything to do in case of textarea. I was debugging (console logging) your script and I believe the rangeCount was 0. - No,
active.blurdidn't throw an exception. In fact no error could be seen in console even if debug mode for you script was set to true.
It's just that active.blur doesn't deslect the selected text in textarea.
I understand you use two methods to deselect text a) normal selection by working with selection and ranges b) active.blur for inputs and textareas. It just looks that method b) just doesn't work for disabled textarea.
I believe the rangeCount was 0.
Then, here's your culprit as it's the first thing that is being checked whenever we go into function