Are multiple identical selectors in a keymap valid?


#1

I wanted to override the keybinding for Ctrl-Alt-P in my user keymap. It seemed straightforward enough, but it didn’t seem to be working.

I’ll walk you through my debugging step-by-step so you can point out if I did anything dumb along the way – note that all of the following was done in safe mode with my previous keymap commented out to try and prevent polluting the environment.

I first sanity check that the default command runs before I modify anything:

Good start. I add my modified keybinding:

Wonderful. Unlike my actual keymap, the override worked. So I probe further…:

The second keybinding overrode the first as expected. This is all going too well. So I try a different key combination on the same selector:

… Huh. I had assumed that the different key combinations would be merged, but instead the newest selector has completely overwritten the first two, restoring the default command.

Sure enough, if I consolidate all of my overrides and de-dupe the selectors, everything works as expected.

I’m running Atom 1.6.0-beta8 on Windows 10 x64. I’ve also had problems performing the same overrides with the same Atom version on Linux (although I have not performed the same detailed investigation I have here to verify the issue is identical).

Is the above behaviour intended?

I read through the in-depth keymaps docs but must admit I didn’t see any warning to not have multiple identical selectors. The fact that the key snippet, recommended in the default user keymap’s header itself, also creates a selector makes it seem like this isn’t intended.

The reason I had multiple identical selectors in the first place is because I like to separate the overrides in my keymap by purpose. Sometimes that purpose - be it project switching, package development, opening files as a few examples – involves overriding keybindings at multiple selectors, and I like to keep those together.


#2

CSON works just like JSON. Duplicate keys are ignored. I consider this a bug.


#3

See the FAQ:

It applies to all CSON (and JSON) files.

Also, the warning about this quality of Atom’s configuration files comes much earlier in the “Basic Customization” section:

https://atom.io/docs/latest/using-atom-basic-customization#configuring-with-cson

Unlike CSS’s selectors, CSON’s keys can only be repeated once per object. If there are duplicate keys, then the last usage of that key overwrites all others, as if they weren’t there. The same holds true for Atom’s config files.


#4

Thanks leedohm, that does explain it. I must have forgotten or skipped over that. :rolling_eyes: I’ll go RTM.

This seems worth further discussion in a feature request. Which project would I raise that against? Atom?


#5

You can find the canonical open Issue for this here:


#6

Unfortunately CSON and JSON are standards and hacking one of the parsers is generally not a good idea. The real place to do it would be at repos for the parsers.