Keyboard Shortcut Module
Purpose of this Module Type
A Keyboard Shortcut plugin module defines a keyboard shortcut within Bitbucket Server. A Bitbucket Server keyboard shortcut allows you to perform potentially any action in Bitbucket Server using one or more keyboard strokes – for example, navigating to a repository, viewing commits or browsing files.
Configuration
The root element for the Keyboard Shortcut plugin module is keyboard-shortcut
. It allows the following attributes and child elements for configuration:
Attributes
Name | Required | Description | Default |
---|---|---|---|
key |
The identifier of the plugin module. This key must be unique within the plugin where it is defined.
Sometimes, in other contexts, you may need to uniquely identify a module.
Do this with the complete module key.
A module with key |
N/A | |
i18n-name | The localisation key for the human-readable name of the plugin module. | ||
name | The human-readable name of the plugin module. | The plugin key. | |
hidden |
When hidden='true' , the keyboard shortcut will not appear in the Keyboard
Shortcuts dialog box.
Despite not appearing in the dialog box, hidden keyboard shortcuts can still be accessed via the relevant keystrokes. |
false |
Elements
Name | Required | Description |
---|---|---|
order |
A value that determines the order in which the shortcut appears on the
Keyboard Shortcuts dialog box, with respect to other `keyboard-shortcut`
plugin modules.
For each |
|
description | A human-readable description of this Keyboard Shortcut module. | |
shortcut |
The sequence of keystrokes required to activate the keyboard shortcut. These
should be presented in the order that the keys are pressed on a keyboard. For
example, gb represents a keyboard shortcut activated by pressing 'g ' then
'b ' on the keyboard.
|
|
operation |
Defines the action to take when this shortcut is activated. The available
actions come from AJS.whenIType. The action is specified through the `type`
attribute of the operation element. The text content of this element is used
as a parameter to the AJS.whenIType function being called. Usually the
parameter is a jQuery selector
that specifies the target of the keyboard shortcut.
Some actions take an optional second parameter. If you require specifying
multiple parameters, you may use a strict JSON array as the operation
element's text content, and this will be used as the `arguments` of the
function.
Available types are:
|
|
context |
The context defines which pages the shortcut will be active on.
|
Examples
These examples are taken from Bitbucket Server's pre-defined keyboard shortcuts:
x1...
2<keyboard-shortcut key="shortcut-branch-selector" i18n-name="bitbucket.web.keyboardshortcut.branch.selector" name="Open Branch Selector">
3<description key="bitbucket.web.keyboardshortcut.branch.selector.desc">Change branch/tag</description>
4<shortcut>b</shortcut>
5<operation type="click">#repository-layout-revision-selector</operation>
6<context>branch</context>
7</keyboard-shortcut>
8...
9
10...
11<keyboard-shortcut key="shortcut-commit-move-to-next-file" i18n-name="bitbucket.web.keyboardshortcut.commit.next.file" name="Commit - Open next file">
12<description key="bitbucket.web.keyboardshortcut.commit.next.file.desc">Next file</description>
13<shortcut>j</shortcut>
14<operation type="evaluate">require('util/shortcuts').setup('requestMoveToNextHandler', this, 'j');</operation>
15<context>commit</context>
16</keyboard-shortcut>
17...
Enabling Custom Contexts
Enabling a custom context requires handling of the "register-contexts.keyboardshortcuts" AJS event from JavaScript. In Bitbucket Server, this is also exposed as an event on 'util/events' if you prefer that API.
31AJS.bind("register-contexts.keyboardshortcuts", function(e, data) {
2data.shortcutRegistry.enableContext('my context');
3});
or
31require('util/events').on('stash.widget.keyboard-shortcuts.register-contexts', function(registry) {
2registry.enableContext('my context');
3});