• Packages
  • Themes
  • Documentation
  • Blog
  • Discuss
Sign in
Whoops, there was an error
v1.34.0
v1.33.1
v1.33.0
v1.32.2
v1.32.1
v1.32.0
v1.31.2
v1.31.1
v1.31.0
v1.30.0
v1.29.0
v1.28.2
v1.28.1
v1.28.0
untagged-688de6479cca05b51c00
untagged-2abd5a23b4430027c837
v1.27.2
v1.27.1
v1.27.0
v1.26.1
v1.26.0
v1.25.1
v1.25.0
v1.24.1
v1.24.0
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.22.1
v1.22.0
v1.21.2
v1.21.1
v1.21.0
v1.20.1
v1.20.0
v1.19.7
v1.19.6
v1.19.5
v1.19.4
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.18.0
v1.17.2
v1.17.1
v1.17.0
v1.16.0
v1.15.0
v1.14.4
v1.14.3
v1.14.2
v1.14.1
v1.14.0
v1.13.1
v1.13.0
v1.12.9
v1.12.8
v1.12.7
v1.12.6
v1.12.5
v1.12.4
v1.12.3
v1.12.2
v1.12.1
v1.12.0
v1.11.2
v1.11.1
v1.11.0
v1.10.2
v1.10.1
v1.10.0
v1.9.9
v1.9.8
v1.9.7
v1.9.6
v1.9.5
v1.9.4
v1.9.3
v1.9.2
v1.9.1
v1.9.0
v1.8.0
v1.7.4
v1.7.3
v1.7.2
v1.7.1
v1.7.0
v1.6.2
v1.6.1
v1.6.0
v1.5.4
v1.5.3
v1.5.2
v1.5.1
v1.5.0
v1.4.3
v1.4.2
v1.4.1
v1.4.0
v1.3.3
v1.3.2
v1.3.1
v1.3.0
v1.2.4
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.1.0
v1.0.19
v1.0.18
v1.0.17
v1.0.16
v1.0.15
v1.0.14
v1.0.13
v1.0.12
v1.0.11
v1.0.10
v1.0.9
v1.0.8
v1.0.7
v1.0.6
v1.0.5
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
v0.211.0
v0.210.0
v0.209.0
v0.208.0
v0.207.0
v0.206.0
v0.205.0
v0.204.0
v0.203.0
v0.202.0
v0.201.0
v0.200.0
v0.199.0
v0.198.0
v0.197.0
v0.196.0
v0.195.0
v0.194.0
v0.193.0
v0.192.0
v0.191.0
v0.190.0
v0.189.0
v0.188.0
v0.187.0
Loading…

Essential Classes

  • AtomEnvironment
  • Color
  • CommandRegistry
  • CompositeDisposable
  • Config
  • Decoration
  • DisplayMarker
  • DisplayMarkerLayer
  • Disposable
  • Emitter
  • LayerDecoration
  • MarkerLayer
  • Notification
  • NotificationManager
  • Point
  • Range
  • TextEditor
  • TooltipManager
  • ViewRegistry
  • Workspace
  • WorkspaceCenter

Extended Classes

  • BufferedNodeProcess
  • BufferedProcess
  • Clipboard
  • ContextMenuManager
  • Cursor
  • DeserializerManager
  • Directory
  • Dock
  • File
  • GitRepository
  • Grammar
  • GrammarRegistry
  • Gutter
  • HistoryManager
  • KeymapManager
  • MenuManager
  • Package
  • PackageManager
  • Pane
  • Panel
  • PathWatcher
  • Project
  • ScopeDescriptor
  • Selection
  • StyleManager
  • Task
  • TextBuffer
  • ThemeManager

CommandRegistry essential

Associates listener functions with commands in a context-sensitive way using CSS selectors. You can access a global instance of this class via atom.commands, and commands registered there will be presented in the command palette.

The global command registry facilitates a style of event handling known as event delegation that was popularized by jQuery. Atom commands are expressed as custom DOM events that can be invoked on the currently focused element via a key binding or manually via the command palette. Rather than binding listeners for command events directly to DOM nodes, you instead register command event listeners globally on atom.commands and constrain them to specific kinds of elements with CSS selectors.

Command names must follow the namespace:action pattern, where namespace will typically be the name of your package, and action describes the behavior of your command. If either part consists of multiple words, these must be separated by hyphens. E.g. awesome-package:turn-it-up-to-eleven. All words should be lowercased.

As the event bubbles upward through the DOM, all registered event listeners with matching selectors are invoked in order of specificity. In the event of a specificity tie, the most recently registered listener is invoked first. This mirrors the "cascade" semantics of CSS. Event listeners are invoked in the context of the current DOM node, meaning this always points at event.currentTarget. As is normally the case with DOM events, stopPropagation and stopImmediatePropagation can be used to terminate the bubbling process and prevent invocation of additional listeners.

Example

Here is a command that inserts the current date in an editor:

atom.commands.add 'atom-text-editor',
  'user:insert-date': (event) ->
    editor = @getModel()
    editor.insertText(new Date().toLocaleString())

Methods

::add(target, commandName, listener)

Add one or more command listeners associated with a selector.

Registering One Command

add(target, commandName, listener)
Argument Description
target

A String containing a CSS selector or a DOM element. If you pass a selector, the command will be globally associated with all matching elements. The , combinator is not currently supported. If you pass a DOM element, the command will be associated with just that element.

commandName

A String containing the name of a command you want to handle such as user:insert-date.

listener(displayName, description, hiddenInCommandPalette)

A listener which handles the event. Either a Function to call when the given command is invoked on an element matching the selector, or an Object with a didDispatch property which is such a function. The function (listener itself if it is a function, or the didDispatch method if listener is an object) will be called with this referencing the matching DOM node and the following argument: Additionally, listener may have additional properties which are returned to those who query using atom.commands.findCommands, as well as several meaningful metadata properties:

displayName

Overrides any generated displayName that would otherwise be generated from the event name.

description

Used by consumers to display detailed information about the command.

hiddenInCommandPalette

If true, this command will not appear in the bundled command palette by default, but can still be shown with. the Command Palette: Show Hidden Commands command. This is a good option when you need to register large numbers of commands that don't make sense to be executed from the command palette. Please use this option conservatively, as it could reduce the discoverability of your package's commands.

Registering Multiple Commands

add(target, commands)
Argument Description
target

A String containing a CSS selector or a DOM element. If you pass a selector, the commands will be globally associated with all matching elements. The , combinator is not currently supported. If you pass a DOM element, the command will be associated with just that element.

commands

An Object mapping command names like user:insert-date to listener Functions.

Return values

Returns a Disposable on which .dispose() can be called to remove the added command handler(s).

::findCommands(params)

Find all registered commands matching a query.

Argument Description
params

An Object containing one or more of the following keys:

.target

A DOM node that is the hypothetical target of a given command.

Return values

Returns an Array of CommandDescriptor Objects containing the following keys:

  • name The name of the command. For example, user:insert-date.
  • displayName The display name of the command. For example, User: Insert Date. Additional metadata may also be present in the returned descriptor:
  • description a String describing the function of the command in more detail than the title
  • tags an Array of Strings that describe keywords related to the command Any additional nonstandard metadata provided when the command was added may also be present in the returned descriptor.

::dispatch(target, commandName)

Simulate the dispatch of a command on a DOM node.

This can be useful for testing when you want to simulate the invocation of a command on a detached DOM node. Otherwise, the DOM node in question needs to be attached to the document so the event bubbles up to the root node to be processed.

Argument Description
target

The DOM node at which to start bubbling the command event.

commandName

String indicating the name of the command to dispatch.

::onWillDispatch(callback)

Invoke the given callback before dispatching a command event.

Argument Description
callback(event)

Function to be called before dispatching each command

event

The Event that will be dispatched

::onDidDispatch(callback)

Invoke the given callback after dispatching a command event.

Argument Description
callback(event)

Function to be called after dispatching each command

event

The Event that was dispatched

  • Terms of Use
  • Privacy
  • Code of Conduct
  • Releases
  • FAQ
  • Contact
with by