Add support for "Ctrl + Enter" and "Meta (Cmd) + Enter" submit on multi-line fields

This commit is contained in:
Molkobain
2022-10-01 16:16:25 +02:00
parent 2dccedf8d7
commit 5e0698b7f3
5 changed files with 61 additions and 16 deletions

View File

@@ -6,6 +6,18 @@
// WARNING: This code cannot be placed directly within the page as CKEditor could not be loaded yet.
// As it can be loaded from an XHR call (several times), we need to ensure it will be called when necessary (see PHP WebResourcesHelper)
CKEDITOR.on('instanceReady', function (oEvent) {
// Keyboard listener
oEvent.editor.on('key', function(oKeyEvent){
const oKeyboardEvent = oKeyEvent.data.domEvent.$;
// Submit value on "Ctrl + Enter" or "Meta (Cmd) + Enter" keyboard shortcut
if ((oKeyboardEvent.ctrlKey || oKeyboardEvent.metaKey) && oKeyboardEvent.key === 'Enter') {
$('#'+ oEvent.editor.name).closest('form').trigger('submit');
}
});
});
// For disabling the CKEditor at init time when the corresponding textarea is disabled !
if ((CKEDITOR !== undefined) && (CKEDITOR.plugins.registered['disabler'] === undefined)) {
CKEDITOR.plugins.add( 'disabler',