@ -1,5 +1,6 @@
import $ from 'jquery' ;
import $ from 'jquery' ;
import attachTribute from '../tribute.js' ;
import attachTribute from '../tribute.js' ;
import { handleGlobalEnterQuickSubmit } from '../common-global.js' ;
/ * *
/ * *
* @ returns { EasyMDE }
* @ returns { EasyMDE }
@ -71,9 +72,12 @@ export async function createCommentEasyMDE(textarea, easyMDEOptions = {}) {
title : 'Revert to simple textarea' ,
title : 'Revert to simple textarea' ,
} ,
} ,
] , ... easyMDEOptions } ) ;
] , ... easyMDEOptions } ) ;
const inputField = easyMDE . codemirror . getInputField ( ) ;
const inputField = easyMDE . codemirror . getInputField ( ) ;
inputField . classList . add ( 'js-quick-submit' ) ;
easyMDE . codemirror . setOption ( 'extraKeys' , {
easyMDE . codemirror . setOption ( 'extraKeys' , {
'Cmd-Enter' : codeMirrorQuickSubmit ,
'Ctrl-Enter' : codeMirrorQuickSubmit ,
Enter : ( cm ) => {
Enter : ( cm ) => {
const tributeContainer = document . querySelector ( '.tribute-container' ) ;
const tributeContainer = document . querySelector ( '.tribute-container' ) ;
if ( ! tributeContainer || tributeContainer . style . display === 'none' ) {
if ( ! tributeContainer || tributeContainer . style . display === 'none' ) {
@ -149,3 +153,12 @@ export function validateTextareaNonEmpty($textarea) {
$mdeInputField . prop ( 'required' , false ) ;
$mdeInputField . prop ( 'required' , false ) ;
return true ;
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 ( ) ) ;
}