From e087bb718c828cc4075308e586366bbae39d4340 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Tue, 3 Oct 2023 18:55:38 +0300 Subject: [PATCH] Add support for bullet list hotkey --- html-editor-lib.pl | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/html-editor-lib.pl b/html-editor-lib.pl index 6c00b0b6d..9abe0088e 100644 --- a/html-editor-lib.pl +++ b/html-editor-lib.pl @@ -277,24 +277,36 @@ my $html_editor_init_script = theme: 'snow' }); - // Google Mail editor like keybind for quoting + // Google Mail like key bind for creating bullet list (Ctrl+Shift+8) editor.keyboard.addBinding({ - key: '9', - shiftKey: true, - ctrlKey: !isMac, - metaKey: isMac, - format: ['blockquote'], + key: '8', + shiftKey: true, + ctrlKey: !isMac, + metaKey: isMac, }, function(range, context) { - this.quill.format('blockquote', false); + const currentFormat = this.quill.getFormat(range.index); + if (currentFormat.list === 'bullet') { + this.quill.format('list', false); + } else { + this.quill.format('list', 'bullet'); + } }); + + // Google Mail like key bind for creating blockquote (Ctrl+Shift+9) editor.keyboard.addBinding({ - key: '9', - shiftKey: true, - ctrlKey: !isMac, - metaKey: isMac, + key: '9', + shiftKey: true, + ctrlKey: !isMac, + metaKey: isMac, }, function(range, context) { - this.quill.format('blockquote', true); + const currentFormat = this.quill.getFormat(range.index); + if (currentFormat.blockquote) { + this.quill.format('blockquote', false); + } else { + this.quill.format('blockquote', true); + } }); + editor.on('text-change', function() { // This should most probably go to onSubmit event targ.value = editor.root.innerHTML + "
";