Hooks ‹ Chocolat API

Hooks.addMenuItem(path, shortcut, callback)

Add a menu item at the given path.

  • path String – the path of the new menu item.
  • shortcut String – keyboard shortcut, e.g. "ctrl-alt-cmd-b".
  • callback Function – a callback to be executed when the menu item is clicked.

Hooks.addKeyboardShortcut(shortcut, callback)

Add a keyboard shortcut.

  • shortcut String – the keyboard shortcut, e.g. "ctrl-alt-cmd-b"
  • callback Function – the callback function to execute.

Hooks.addContextMenuItem(location, title, options, callback)

Add a context menu item.

  • location String – what kind of context menu to show the item in. Currently the only valid value is `'editor'`.
  • title String – the title of the menu item.
  • options Object – Valid options are `'scope'` (a scope selector), and `'shortcut'`. Optional.
  • callback Function – a callback to be executed when the menu item is clicked.

Hooks.onInsertText(Editor))

Modify the text as the user types it. Warning: can make typing things slower.

  • Editor) Function(String or – -> String} callback The callback function to be called when the user types. Takes two arguments, the string typed and an instance of Editor in which the change will occur.

Hooks.setShortcutForMenuItem(path, shortcut)

Remap a menu item to a new keyboard shortcut.

  • path String – the path of the menu item to change.
  • shortcut String – keyboard shortcut, e.g. "ctrl-alt-cmd-b".

Example

Hooks.setShortcutForMenuItem("Go/Go To File...", "cmd-t");