mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 07:45:51 +01:00
Initial implementation of the plugin.
This commit is contained in:
45
src/KbdUI.js
Normal file
45
src/KbdUI.js
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
||||
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
|
||||
|
||||
import kbdIcon from '../icons/kbd.svg';
|
||||
|
||||
const KBD = 'kbd';
|
||||
|
||||
/**
|
||||
* The keyboard shortcut UI feature. It brings a proper button.
|
||||
*
|
||||
* @extends module:core/plugin~Plugin
|
||||
*/
|
||||
export default class KbdUI extends Plugin {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
init() {
|
||||
const editor = this.editor;
|
||||
const t = editor.t;
|
||||
|
||||
editor.ui.componentFactory.add( KBD, locale => {
|
||||
const command = editor.commands.get( KBD );
|
||||
const view = new ButtonView( locale );
|
||||
|
||||
view.set( {
|
||||
label: t( 'Keyboard shortcut' ),
|
||||
icon: kbdIcon,
|
||||
keystroke: 'ALT+SHIFT+K',
|
||||
tooltip: true,
|
||||
isToggleable: true
|
||||
} );
|
||||
|
||||
view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
|
||||
|
||||
// Execute command.
|
||||
this.listenTo( view, 'execute', () => {
|
||||
editor.execute( KBD );
|
||||
editor.editing.view.focus();
|
||||
} );
|
||||
|
||||
return view;
|
||||
} );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user