8393c01be9
Closes #2984, #3020 Ref #1463, #3019 #### Shortcut Values Shortcut values can now be either strings (as before) or objects like {action:string, options:hash}. #### Markdown shortcuts added - 'ctrl+alt+u' strkethrough - 'ctrl+alt+1' h1 - 'ctrl+alt+2' h2 - 'ctrl+alt+3' h3 - 'ctrl+alt+4' h4 - 'ctrl+alt+5' h5 - 'ctrl+alt+6' h6 - 'ctrl+shift+i' image - 'ctrl/command+k' link - 'ctrl+l' list Left behind commented out stubs for additional markdown shortcuts. #### Editor Controllers (New and Edit) - Moved shared init function into editor-base-controller. - Removed MarkerManager mixin from editor controllers as it's included in the base.
76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
/* global key, console */
|
|
|
|
//Configure KeyMaster to respond to all shortcuts,
|
|
//even inside of
|
|
//input, textarea, and select.
|
|
key.filter = function () {
|
|
return true;
|
|
};
|
|
|
|
/**
|
|
* Only routes can implement shortcuts.
|
|
* If you need to trigger actions on the controller,
|
|
* simply call them with `this.get('controller').send('action')`.
|
|
*
|
|
* To implement shortcuts, add this mixin to your `extend()`,
|
|
* and implement a `shortcuts` hash.
|
|
* In this hash, keys are shortcut combinations and values are route action names.
|
|
* (see [keymaster docs](https://github.com/madrobby/keymaster/blob/master/README.markdown)),
|
|
*
|
|
* ```javascript
|
|
* shortcuts: {
|
|
* 'ctrl+s, command+s': 'save',
|
|
* 'ctrl+alt+z': 'toggleZenMode'
|
|
* }
|
|
* ```
|
|
* For more complex actions, shortcuts can instead have their value
|
|
* be an object like {action, options}
|
|
* ```javascript
|
|
* shortcuts: {
|
|
* 'ctrl+k': {action: 'markdownShortcut', options: 'createLink'}
|
|
* }
|
|
* ```
|
|
*/
|
|
var ShortcutsRoute = Ember.Mixin.create({
|
|
registerShortcuts: function () {
|
|
var self = this,
|
|
shortcuts = this.get('shortcuts');
|
|
|
|
Ember.keys(shortcuts).forEach(function (shortcut) {
|
|
key(shortcut, function (event) {
|
|
var action = shortcuts[shortcut],
|
|
options;
|
|
if (Ember.typeOf(action) !== 'string') {
|
|
options = action.options;
|
|
action = action.action;
|
|
}
|
|
|
|
//stop things like ctrl+s from actually opening a save dialogue
|
|
event.preventDefault();
|
|
self.send(action, options);
|
|
});
|
|
});
|
|
},
|
|
removeShortcuts: function () {
|
|
var shortcuts = this.get('shortcuts');
|
|
|
|
Ember.keys(shortcuts).forEach(function (shortcut) {
|
|
key.unbind(shortcut);
|
|
});
|
|
},
|
|
activate: function () {
|
|
this._super();
|
|
if (!this.shortcuts) {
|
|
console.error('Shortcuts not found on route');
|
|
return;
|
|
}
|
|
this.registerShortcuts();
|
|
},
|
|
deactivate: function () {
|
|
this._super();
|
|
this.removeShortcuts();
|
|
}
|
|
});
|
|
|
|
export default ShortcutsRoute;
|