• 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

KeymapManager extended

Allows commands to be associated with keystrokes in a context-sensitive way. In Atom, you can access a global instance of this object via atom.keymaps.

Key bindings are plain JavaScript objects containing CSS selectors as their top level keys, then keystroke patterns mapped to commands.

'.workspace':
  'ctrl-l': 'package:do-something'
  'ctrl-z': 'package:do-something-else'
'.mini.editor':
  'enter': 'core:confirm'

When a keystroke sequence matches a binding in a given context, a custom DOM event with a type based on the command is dispatched on the target of the keyboard event.

To match a keystroke sequence, the keymap starts at the target element for the keyboard event. It looks for key bindings associated with selectors that match the target element. If multiple match, the most specific is selected. If there is a tie in specificity, the most recently added binding wins. If no bindings are found for the events target, the search is repeated again for the target's parent node and so on recursively until a binding is found or we traverse off the top of the document.

When a binding is found, its command event is always dispatched on the original target of the keyboard event, even if the matching element is higher up in the DOM. In addition, .preventDefault() is called on the keyboard event to prevent the browser from taking action. .preventDefault is only called if a matching binding is found.

Command event objects have a non-standard method called .abortKeyBinding(). If your command handler is invoked but you programmatically determine that no action can be taken and you want to allow other bindings to be matched, call .abortKeyBinding() on the event object. An example of where this is useful is binding snippet expansion to tab. If snippets:expand is invoked when the cursor does not follow a valid snippet prefix, we abort the binding and allow tab to be handled by the default handler, which inserts whitespace.

Multi-keystroke bindings are possible. If a sequence of one or more keystrokes partially matches a multi-keystroke binding, the keymap enters a pending state. The pending state is terminated on the next keystroke, or after ::getPartialMatchTimeout milliseconds has elapsed. When the pending state is terminated via a timeout or a keystroke that leads to no matches, the longest ambiguous bindings that caused the pending state are temporarily disabled and the previous keystrokes are replayed. If there is ambiguity again during the replay, the next longest bindings are disabled and the keystrokes are replayed again.

Class Methods

.buildKeydownEvent(key, [options])

Create a keydown DOM event for testing purposes.

Argument Description
key

The key or keyIdentifier of the event. For example, 'a', '1', 'escape', 'backspace', etc.

options optional

An Object containing any of the following:

.ctrl

A Boolean indicating the ctrl modifier key

.alt

A Boolean indicating the alt modifier key

.shift

A Boolean indicating the shift modifier key

.cmd

A Boolean indicating the cmd modifier key

.which

A Number indicating which value of the event. See the docs for KeyboardEvent for more information.

.target

The target element of the event.

Construction and Destruction

::constructor(options)

Create a new KeymapManager.

Argument Description
options

An Object containing properties to assign to the keymap. You can pass custom properties to be used by extension methods. The following properties are also supported:

.defaultTarget

This will be used as the target of events whose target is document.body to allow for a catch-all element when nothing is focused.

::clear()

Clear all registered key bindings and enqueued keystrokes. For use in tests.

::destroy()

Unwatch all watched paths.

Event Subscription

::onDidMatchBinding(callback)

Invoke the given callback when one or more keystrokes completely match a key binding.

Argument Description
callback(event)

Function to be called when keystrokes match a binding.

event

Object with the following keys:

.keystrokes

String of keystrokes that matched the binding.

.binding

KeyBinding that the keystrokes matched.

.keyboardEventTarget

DOM element that was the target of the most recent keyboard event.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onDidPartiallyMatchBindings(callback)

Invoke the given callback when one or more keystrokes partially match a binding.

Argument Description
callback(event)

Function to be called when keystrokes partially match a binding.

event

Object with the following keys:

.keystrokes

String of keystrokes that matched the binding.

.partiallyMatchedBindings

KeyBindings that the keystrokes partially matched.

.keyboardEventTarget

DOM element that was the target of the most recent keyboard event.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onDidFailToMatchBinding(callback)

Invoke the given callback when one or more keystrokes fail to match any bindings.

Argument Description
callback(event)

Function to be called when keystrokes fail to match any bindings.

event

Object with the following keys:

.keystrokes

String of keystrokes that matched the binding.

.keyboardEventTarget

DOM element that was the target of the most recent keyboard event.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onDidFailToReadFile(callback)

Invoke the given callback when a keymap file not able to be loaded.

Argument Description
callback(error)

Function to be called when a keymap file is unloaded.

error

Object with the following keys:

.message

String the error message.

.stack

String the error stack trace.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

Adding and Removing Bindings

::build(source, bindings, priority)

Construct KeyBindings from an object grouping them by CSS selector.

Argument Description
source

A String (usually a path) uniquely identifying the given bindings so they can be removed later.

bindings

An Object whose top-level keys point at sub-objects mapping keystroke patterns to commands.

priority

A Number used to sort keybindings which have the same specificity. Defaults to 0.

::add(source, bindings, priority)

Add sets of key bindings grouped by CSS selector.

Argument Description
source

A String (usually a path) uniquely identifying the given bindings so they can be removed later.

bindings

An Object whose top-level keys point at sub-objects mapping keystroke patterns to commands.

priority

A Number used to sort keybindings which have the same specificity. Defaults to 0.

Accessing Bindings

::getKeyBindings()

Get all current key bindings.

Return values

Returns an Array of KeyBindings.

::findKeyBindings(params)

Get the key bindings for a given command and optional target.

Argument Description
params

An Object whose keys constrain the binding search:

.keystrokes

A String representing one or more keystrokes, such as 'ctrl-x ctrl-s'

.command

A String representing the name of a command, such as 'editor:backspace'

.target

An optional DOM element constraining the search. If this parameter is supplied, the call will only return bindings that can be invoked by a KeyboardEvent originating from the target element.

Return values

Returns an Array of key bindings.

Managing Keymap Files

::loadKeymap(path, options)

Load the key bindings from the given path.

Argument Description
path

A String containing a path to a file or a directory. If the path is a directory, all files inside it will be loaded.

options

An Object containing the following optional keys:

.watch

If true, the keymap will also reload the file at the given path whenever it changes. This option cannot be used with directory paths.

.priority

A Number used to sort keybindings which have the same specificity.

::watchKeymap(path, options)

Cause the keymap to reload the key bindings file at the given path whenever it changes.

This method doesn't perform the initial load of the key bindings file. If that's what you're looking for, call ::loadKeymap with watch: true.

Argument Description
path

A String containing a path to a file or a directory. If the path is a directory, all files inside it will be loaded.

options

An Object containing the following optional keys:

.priority

A Number used to sort keybindings which have the same specificity.

Managing Keyboard Events

::handleKeyboardEvent(event)

Dispatch a custom event associated with the matching key binding for the given KeyboardEvent if one can be found.

If a matching binding is found on the event's target or one of its ancestors, .preventDefault() is called on the keyboard event and the binding's command is emitted as a custom event on the matching element.

If the matching binding's command is 'native!', the method will terminate without calling .preventDefault() on the keyboard event, allowing the browser to handle it as normal.

If the matching binding's command is 'unset!', the search will continue from the current element's parent.

If the matching binding's command is 'abort!', the search will terminate without dispatching a command event.

If the event's target is document.body, it will be treated as if its target is .defaultTarget if that property is assigned on the keymap.

Argument Description
event

A KeyboardEvent of type 'keydown'

::keystrokeForKeyboardEvent(event)

Translate a keydown event to a keystroke string.

Argument Description
event

A KeyboardEvent of type 'keydown'

Return values

Returns a String describing the keystroke.

::addKeystrokeResolver(resolver)

Customize translation of raw keyboard events to keystroke strings. This API is useful for working around Chrome bugs or changing how Atom resolves certain key combinations. If multiple resolvers are installed, the most recently-added resolver returning a string for a given keystroke takes precedence.

Argument Description
resolver(keystroke, event, layoutName, keymap)

A Function that returns a keystroke String and is called with an object containing the following keys:

keystroke

The currently resolved keystroke string. If your function returns a falsy value, this is how Atom will resolve your keystroke.

event

The raw DOM 3 KeyboardEvent being resolved. See the DOM API documentation for more details.

layoutName

The OS-specific name of the current keyboard layout.

keymap

An object mapping DOM 3 KeyboardEvent.code values to objects with the typed character for that key in each modifier state, based on the current operating system layout.

Return values

Returns a Disposable that removes the added resolver.

::getPartialMatchTimeout()

Get the number of milliseconds allowed before pending states caused by partial matches of multi-keystroke bindings are terminated.

Return values

Returns a Number

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