From b6c86ea2179027e06f834d7569a6110beb76e72f Mon Sep 17 00:00:00 2001 From: Lee Dohm Date: Tue, 3 Feb 2015 04:31:23 -0800 Subject: [PATCH] :memo: Update command example for CommandRegistry --- docs/advanced/keymaps.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/docs/advanced/keymaps.md b/docs/advanced/keymaps.md index e47d8d860..351dfaf5f 100644 --- a/docs/advanced/keymaps.md +++ b/docs/advanced/keymaps.md @@ -49,19 +49,17 @@ can be expressed as keystroke patterns separated by spaces. Commands are custom DOM events that are triggered when a keystroke matches a binding. This allows user interface code to listen for named commands without specifying the specific keybinding that triggers it. For example, the following -code sets up {EditorView} to listen for commands to move the cursor to the first -character of the current line: +code creates a command to insert the current date in an editor: ```coffee -class EditorView - listenForEvents: -> - @command 'editor:move-to-first-character-of-line', => - @editor.moveToFirstCharacterOfLine() +atom.commands.add 'atom-text-editor', + 'user:insert-date': (event) -> + editor = @getModel() + editor.insertText(new Date().toLocaleString()) ``` -The `::command` method is basically an enhanced version of jQuery's `::on` -method that listens for a custom DOM event and adds some metadata to the DOM, -which is read by the command palette. +`atom.commands` refers to the global {CommandRegistry} instance where all commands +are set and consequently picked up by the command palette. When you are looking to bind new keys, it is often useful to use the command palette (`ctrl-shift-p`) to discover what commands are being listened for in a