diff options
Diffstat (limited to 'web_src/js/features/comp/EasyMDE.js')
-rw-r--r-- | web_src/js/features/comp/EasyMDE.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/web_src/js/features/comp/EasyMDE.js b/web_src/js/features/comp/EasyMDE.js index 0327a1e023..61aaf23e89 100644 --- a/web_src/js/features/comp/EasyMDE.js +++ b/web_src/js/features/comp/EasyMDE.js @@ -1,5 +1,6 @@ import $ from 'jquery'; import attachTribute from '../tribute.js'; +import {handleGlobalEnterQuickSubmit} from '../common-global.js'; /** * @returns {EasyMDE} @@ -71,9 +72,12 @@ export async function createCommentEasyMDE(textarea, easyMDEOptions = {}) { title: 'Revert to simple textarea', }, ], ...easyMDEOptions}); + const inputField = easyMDE.codemirror.getInputField(); - inputField.classList.add('js-quick-submit'); + easyMDE.codemirror.setOption('extraKeys', { + 'Cmd-Enter': codeMirrorQuickSubmit, + 'Ctrl-Enter': codeMirrorQuickSubmit, Enter: (cm) => { const tributeContainer = document.querySelector('.tribute-container'); if (!tributeContainer || tributeContainer.style.display === 'none') { @@ -149,3 +153,12 @@ export function validateTextareaNonEmpty($textarea) { $mdeInputField.prop('required', false); return true; } + +/** + * there is no guarantee that the CodeMirror object is inside the same form as the textarea, + * so can not call handleGlobalEnterQuickSubmit directly. + * @param {CodeMirror.EditorFromTextArea} codeMirror + */ +export function codeMirrorQuickSubmit(codeMirror) { + handleGlobalEnterQuickSubmit(codeMirror.getTextArea()); +} |