dhruvtv / copylinkaddress

Chrome extension to copy link address using keyboard.
https://chrome.google.com/webstore/detail/copy-link-address/kdejdkdjdoabfihpcjmgjebcpfbhepmh
47 stars 9 forks source link

Hovering over a link will make focused input lose focus #2

Open DanielSmedegaardBuus opened 11 years ago

DanielSmedegaardBuus commented 11 years ago

Hi :)

I noticed that with the extension active, whenever I click an input field to focus it and then move the cursor away (which I seem to do a lot, both on purpose and by mistake if i bump my mouse with my hand on the way to the keyboard) and it then hovers any link, the input field will lose focus and I'll lose whatever input I started typing.

dhruvtv commented 11 years ago

Thanks for reporting the issue!

Short answer: Unfortunately, this behavior is the side effect of the core implementation of the extension. The best I can do right now is to restore your cursor position when you move away from the link.

Long answer: The way the extension works is, once you hover a link: If something is already selected in the page, it does nothing. Else, it takes the URL of the link you are hovering, copies it to an invisible span, programmatically selects the span.

Now when you hits Cmd-C (Ctrl-C), the hidden selection is copied to clipboard.

When you move pointer away from the link, it clears the hidden selection, clears the invisible span.

If, at the time of hover, the cursor was in a textbox (without anything selected), it is technically a zero-length selection in Chrome. So, the extension goes ahead and clears that selection (thereby taking the cursor away from the textbox), saving the caret position. When you move away from the link, the caret position is restored.

So, what do we do now? I'm considering adding a 'Settings' page where you can say 'Do not bother if my cursor is currently in a textbox'. What do you think?

DanielSmedegaardBuus commented 11 years ago

Woops, sorry for the incredibly long time before returning — my inbox is a mess! :D

Anyway, I think that sounds like a great idea :)

And thanks for the explanation! Very ncie :+1: