mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
0cbd7d5c68
no issue - move all existing markdown editor behaviour out of the editor controller and isolate it into a single component that can be swapped out - split the `register/remove` functions of the `shortcuts-route` out into a separate `shortcuts` mixin
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
import Ember from 'ember';
|
|
import ShortcutsMixin from 'ghost/mixins/shortcuts';
|
|
|
|
const {Mixin} = Ember;
|
|
|
|
/**
|
|
* 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'}
|
|
* }
|
|
* ```
|
|
* You can set the scope of your shortcut by passing a scope property.
|
|
* ```javascript
|
|
* shortcuts : {
|
|
* 'enter': {action : 'confirmModal', scope: 'modal'}
|
|
* }
|
|
* ```
|
|
* If you don't specify a scope, we use a default scope called "default".
|
|
* To have all your shortcut work in all scopes, give it the scope "all".
|
|
* Find out more at the keymaster docs
|
|
*/
|
|
export default Mixin.create(ShortcutsMixin, {
|
|
activate() {
|
|
this._super(...arguments);
|
|
this.registerShortcuts();
|
|
},
|
|
|
|
deactivate() {
|
|
this._super(...arguments);
|
|
this.removeShortcuts();
|
|
}
|
|
});
|