I am reading the contents of a selection to the clipboard using document.execCommand('copy')
, and then assigning it to a variable.
There is a possibility that the user will not have any text selected, and instead will simply have clicked in the area.
In that case, the previous contents of the clipboard remain unchanged, since the copy command won’t execute unless there is actually a selection.
Is there a way for me to determine when the selection is empty?
I have could compare the previous and current values of the clipboard, and when they are the same, assigning the selection variable to an empty string, but there could be some edge cases where the selection and the clipboard contents are legitimately the same, and in that case, the function would not work properly.