MakeBetter / Units

Enhanced navigation on the web
1 stars 0 forks source link

selectAnyLink: Unable to target links using space + <key> if <key> is bound as a shortcut: Keydown vs keypress issue #141

Closed ghost closed 11 years ago

ghost commented 11 years ago

E.g: Unable to target links beginning with 'J' using space + J since 'J' is bound as the shortcut for scroll down/next CU

This issue doesn't occur if keydown is used for binding the spacePlusKey handler, instead of keypress (however keypress is preferable to keydown since it allows getting the actual character entered when shift is pressed as a modifier)

Weirdly enough, on pressing space + J, the nextCU/scroll down shortcut does not get triggered (which is as expected since they are bound without the space modifier). Yet it prevents the 'keypress' event for space + J from getting triggered.

[The reason for this has been already been identified:

When binding a key using keydown using Mousetrap library, we also bind the associated keypress event. Even so, since the 'space' key is present in these invocations (like space + J) and not in the original binding, there should be no issue.

However, when finding associated callbacks for 'keypress' events, mousetrap only seems to check for control and meta modifiers to match.

The fix requires also checking for the 'space' modifier to match.

Note to self for the future: If replacing mousetrap with a library of your own, we won't need these special cases for 'keypress' etc, if we only enable shortcuts to be specified as + (using only keydown), which is what we are doing at the moment, both in code and the UI for specifying shortcuts.]