Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctrl+Shift+B swaps between the background #4153

Closed
boothym opened this issue Jul 13, 2017 · 5 comments
Closed

Ctrl+Shift+B swaps between the background #4153

boothym opened this issue Jul 13, 2017 · 5 comments
Labels
bug A bug - let's fix this!

Comments

@boothym
Copy link
Contributor

boothym commented Jul 13, 2017

As described here #2492 (comment)

using Ctrl+Shift+B as described in the keyboard shortcuts swaps between the background like when using Ctrl+B.

@bhousel bhousel added the bug A bug - let's fix this! label Jul 13, 2017
@kepta
Copy link
Collaborator

kepta commented Jul 14, 2017

I got some time to look into this bug.

There are two d3keybinding namespaces involved, info and background.

info namespace registers Ctrl+⇧+B

{
    "event": {
      "key": "b",
      "keyCode": 66,
      "modifiers": {
        "shiftKey": true,
        "ctrlKey": false,
        "altKey": false,
        "metaKey": true
      }
    }
  }

and background registers ⇧+B

{
    "event": {
      "key": "b",
      "keyCode": 66,
      "modifiers": {
        "shiftKey": false,
        "ctrlKey": false,
        "altKey": false,
        "metaKey": true
      }
    }
  },

I guess problem seems to lie here https://github.com/openstreetmap/iD/blob/master/modules/lib/d3.keybinding.js#L25
The background's callback gets called when pressed Ctrl+⇧+B, since line gets executed, believing Ctrl+B was pressed.

@bhousel what do you think?

@bhousel
Copy link
Member

bhousel commented Jul 14, 2017

I guess problem seems to lie here https://github.com/openstreetmap/iD/blob/master/modules/lib/d3.keybinding.js#L25
The background's callback gets called when pressed Ctrl+⇧+B, since line gets executed, believing Ctrl+B was pressed.
@bhousel what do you think?

Yeah, it does seem like something not quite right in that code. I would expect didMatch should be true after the ⌘⇧B, so that ⌘B would not be tested.

@kepta
Copy link
Collaborator

kepta commented Jul 17, 2017

@bhousel I might be wrong though, but having a separate namespace would have separate instances of d3keybinding?
And if that is true they would likely have their own didMatch variables?

@bhousel
Copy link
Member

bhousel commented Jul 17, 2017

didMatch is a local variable to the testBindings() function, so every time a key is pressed and iD tries to match a handler, it should start out being false. I think the code can be changed to make it more clear or exit early as soon as a match happens.

@bhousel
Copy link
Member

bhousel commented Jul 17, 2017

I found out what was happening, the key event just gets sent to all of the listeners unless we specifically stop it. This is normal.

I added some stopImmediatePropagation() calls to stop the event from firing after one of the listeners handles it.

I'm a bit uneasy about this because it means that the code is probably order-dependent. So it works as long as ⌘⇧B and ⌘B are registered in the right order, otherwise the ⌘B could potentially override the ⌘⇧B.

I'll think more about this but closing the issue for now..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug - let's fix this!
Projects
None yet
Development

No branches or pull requests

3 participants