Keybinding based on panel visibility?


#1

Is it possible to use selectors to set a keybinding so that it is only active when a specific panel is open.
In my case, I’d like to bind alt-> to go to the next lint error (from the linter package) but only when the linter panel is toggled open. My problem is that I have no idea how to determine a set of available or possible selectors. I would imagine that there is some way of doing it that is akin to the log-cursor-scope function (alt-cmd-p), but I for the life of me can’t figure it out.

Any help would be great. It would be nice to know if there is a general way to find the extant selectors (or intuit what they might be).


#2

It depends on how you mean. The keybinding selectors are designed to define within what areas of the UI a keybinding is available. So if a certain panel is open and you only want the key to work within that panel, then sure … that’s easy. Take a look at some of the tree-view package keybindings for example:

If you’re looking for a keybinding to be available everywhere in the UI, but only when a certain panel is open … that’s a bit tougher. But the keybinding selectors are simply CSS selectors, so if you can do it with CSS selectors then you should be able to do it with Atom’s keybinding system.

The most common selectors used for keybindings are:

  • atom-workspace — Used for keybindings that should be available no matter what area of the editor is focused. Things like File Open or Save All commonly use this type of selector
  • atom-text-editor — Used for keybindings that should be available in any text editor, including the mini text editors for edit controls like in the Settings View or Fuzzy Finder
  • atom-text-editor:not([mini]) — Used for keybindings that should be available only in an open editor
  • .platform-* — Used in combination with one of the above to specify a keybinding only for a certain platform

As I said above, keybinding selectors are CSS selectors. So you can use the standard Chromium development tools that you would use for discovering selectors for styling things.