Keybindings to the Sidebar's "Add file"


#1

Whenever a new file is created with cmd + n, a new tab is created and saving it causes a save dialog to appear. You can see a gif screencast here.

I’ve been looking for a keybinding for the sidebar’s add file so I can replace cmd + n with this so I can directly create files without going through all the extra keystrokes. It’s sorta like the Advanced New File plugin with sublime.

Thanks. :smile:


#2

The command is tree-view:add-file, but I’ve tried creating a global keymap for it and it doesn’t work. (At least the last time I tried it.) I suspect that there is some information in the tree view that it needs to do its job that it doesn’t get when the tree view isn’t focused.

You could take a look at the Tree View package and see what they’re doing …


#3

I’ve also tried creating a key binding for the “Add File” command with no luck. Can anyone with a bit more knowledge of Atom explain why this isn’t working?

'.editor':
  'ctrl-cmd-a': 'tree-view:add-file'

#4

Because the event is only being listened for on the tree view DOM element, https://github.com/atom/tree-view/blob/master/lib/tree-view.coffee#L69

So if it is triggered on the editor (which it will be in your case since the selector is on `.editor), it will bubble up the DOM but never hit the tree view element since it isn’t a parent of the editor view.

I would consider this a bug, would you mind opening this up as an issue on the tree view repo?


#5

So should that command be defined as core? I’m trying to get an understanding of how Atom works.


#6

Well, for now, is it possible to bind multiple actions to a key? For example, I want to bind cmd-n to tree view focus then tree view new file just to simulate that action I guess.


#7

You could create your own command that performed both actions and then bind that command to a key. I’m pretty sure @AbeEstrada has a way to do this, create commands that is, from the init script even.


#8

Try this:

'body':
  'cmd-n': 'tree-view:add-file'

#9

Thanks! Worked like a charm. :slight_smile: