Consider the scenario in which a user is reading a article (e.g.) God. He then opens another article (e.g.) monotheism linked in it, in a new tab using the shortcut Ctrl + click. After reading the article a little he switches back to the tab containing the previous article using the shortcut Ctrl + tab / Ctrl + Shift+ tab. In this case he wouldn't expect to see a link preview but a preview is shown as the keyup listener is triggered by the Control or Shift keys.
To prevent this situation it would be better if the popups aren't shown for when the keyup listener is triggered due to the Control and Shift keys. This shouldn't cause an issue as they seem to be meta-keys and don't much job by themselves.
Proposed solution
We listen to keyup so that we respond to <TAB> presses to show previews on tab. Right now all keys are processed when focused on a link to trigger the linkDwell action.
Using jQuery's event.which, we should whitelist TAB when the event is keyup instead of trying to blacklist all possible shortcut keys for moving around tabs in the browser or processing all of them unconditionally like right now.
Pseudocode:
diff --git a/src/index.js b/src/index.jsowser as it index 0ebe48e..181e66f 100644 --- a/src/index.js +++ b/src/index.js @@ -169,7 +169,8 @@ mw.requestIdleCallback( function () { previewLinks .on( 'mouseover keyup', function ( event ) { + // Skip keyups that are not TAB (T166610) + if (event.type === 'keyup' && event.which !== 9) return; + boundActions.linkDwell( this, event, gateway, generateToken ); } ) .on( 'mouseout blur', function () { boundActions.abandon( this );