Custom Command - Reference Existing Commands


#1

I’m trying to add a custom command to my init.coffee file:

atom.commands.add 'atom-text-editor:not([mini])', 'custom:toggle-line-comments-and-move-on', ->
        atom.commands.dispatch(atom.workspace.getActiveTextEditor(), 'editor:toggle-line-comments')
        atom.commands.dispatch(atom.workspace.getActiveTextEditor(), 'core:move-down')

I have the following in my keymap.cson file:

'atom-text-editor':
  'cmd-/': 'custom:toggle-line-comments-and-move-on'

The keyboard shortcut appears below the core entry when I check keybindings, however, nothing happens. I figure I’m doing something wrong in my init script.

Any pointers to get me back on track?

Thanks!
~Mike


#2

Update: found the solution:

init.coffee

atom.commands.add 'atom-text-editor', 'custom:toggle-line-comments-and-move-on', ->
    editor = atom.views.getView(atom.workspace.getActiveTextEditor())
    return unless editor
    atom.commands.dispatch(editor, 'editor:toggle-line-comments')
    atom.commands.dispatch(editor, 'core:move-down')

keymap.cson:

'atom-workspace atom-text-editor:not([mini])':
  'cmd-/': 'custom:toggle-line-comments-and-move-on'