How can I add a keyboard shortcut for my command in CKEditor 3?

左心房为你撑大大i 提交于 2020-01-03 17:07:51

问题


My plugin defines a command to paste some data and generate a link from it.

Is there any way to make a keyboard shortcut for it? I can't find anything that works.

I cannot get this to work.

Running this from my plugin definition doesn't work either

CKEDITOR.config.keystrokes.append([CKEDITOR.CTRL + CKEDITOR.SHIFT + 108, 'pasteLotusLink']);

Nor trying to get at least bold to work from c-q:

editor.keystrokeHandler.keystrokes[CKEDITOR.CTRL + 113, 'bold'];

回答1:


For 4.x, use editor.setKeystroke:

CKEDITOR.plugins.add( 'foo', {
    init: function( editor ) {
        editor.setKeystroke( CKEDITOR.CTRL + 81, 'bold' ); // CTRL+Q
    }
} );

For 3.x:

CKEDITOR.plugins.add( 'foo', {
    init: function( editor ) {
        editor.on( 'instanceReady', function( evt ) {
            evt.removeListener();
            this.keystrokeHandler.keystrokes[ CKEDITOR.CTRL + 81 ] = 'bold'; // CTRL+Q
        } );
    }
} );


来源:https://stackoverflow.com/questions/17706086/how-can-i-add-a-keyboard-shortcut-for-my-command-in-ckeditor-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!