atom / atom-keymap

Atom's selector-based keymap system
MIT License
105 stars 58 forks source link

More specific selector doesn't override less specific #138

Open tomasbedrich opened 8 years ago

tomasbedrich commented 8 years ago

I have following code in my keymap:

'atom-workspace atom-text-editor[data-grammar~="html"]:not([mini])':
  'cmd-/': 'emmet:toggle-comment'

The Keybindings settings:

keybindings settings

I would expect my User selector should override the less specific Core selector when editing HTML, however the Core keystroke is used when pressing Ctrl-/.

BTW: When I change my selector to be exactly same as Core, it works well. But I want to use the emmet:toggle-comment command only for HTML.

mauricioszabo commented 8 years ago

I've got another way of simulating this: using proto-repl, it'll create an Ink Console when I toggle the plugin. I posted about it in this discussion:

https://discuss.atom.io/t/why-do-user-key-bindings-not-take-priority/11740/7?u=mauricioszabo

Steps to reproduce

I've tried two ways of unsetting the pageup:

'ink-console atom-text-editor':
  'pageup': 'unset!'

'body ink-console atom-text-editor':
  'pageup': 'unset!'

'ink-console atom-text-editor:not(.mini)':
  'pageup': 'unset!'

None of the above worked - pageup keeps being captured by body selector (Atom's default)

The strange thing is that if I try to bind to any other thing, other than "unset", it works.

/cc @lee-dohm

mauricioszabo commented 8 years ago

Other strange thing: one of my keybindings (in the editor) is ctrl-q. The problem is that sometimes, Atom just ignores my keybind and just uses its default, which is... to quit the editor :disappointed:

The following bindings didn't override its defaults:

'body':
    'ctrl-q': 'unset!' # atom understands it, shows on keybinding resolver, but sometimes, ignores it
    'ctrl-q': 'tree-view:toggle' # don't work
    'ctrl-q': 'application:open-file' # don't work either

Now, this is some serious issue - I can't have to sometimes understand my keybindings, and sometimes, not, specially if one of them causes all my open Atom instances to quit. I don't even understand why there's a keybinding for "quit all open atom windows in all namespaces and all projects" in the first place...

winstliu commented 8 years ago

Ctrl+Q, at least for me, doesn't exist on Windows - what OS are you using?

mauricioszabo commented 8 years ago

Arch Linux, but the same happens on Ubuntu 14.10 and 16

winstliu commented 8 years ago

Can you try not unsetting it, like in the following example? I tried it out with ctrl-w which seems to be working.

'body':
  'ctrl-q': 'tree-view:toggle'
mauricioszabo commented 8 years ago

I did a little debugging on this, and found out I was separating keybindings on some sections - all Clojure files should use these keybindings, all ruby, these other, etc.

I found out I had two body clauses, and Atom was ignoring the first. So, probably this case will not happen so often anymore, but still this means I need to disable keybindings in the same selector (and hope that Atom captures the correct one - for example, when I need to upgrade a plugin, I need to restart Atom otherwise the plugin's keybindings overrides mine when it reloads...