@@ -8,7 +8,7 @@ import {handleGlobalEnterQuickSubmit} from './QuickSubmit.js';
88import { emojiString } from '../emoji.js' ;
99import { renderPreviewPanelContent } from '../repo-editor.js' ;
1010import { matchEmoji , matchMention } from '../../utils/match.js' ;
11- import { svg } from '../../svg .js' ;
11+ import { easyMDEToolbarActions } from './EasyMDEToolbarActions .js' ;
1212
1313let elementIdCounter = 0 ;
1414
@@ -206,66 +206,20 @@ class ComboMarkdownEditor {
206206
207207 prepareEasyMDEToolbarActions ( ) {
208208 this . easyMDEToolbarDefault = [
209- 'bold' , 'italic' , 'strikethrough' , '|' , 'heading-1' , 'heading-2' , 'heading-3' , 'heading-bigger' , 'heading-smaller' , '|' ,
210- 'code ' , 'quote ' , '|' , 'gitea-checkbox-empty ' , 'gitea-checkbox-checked ' , '|' ,
211- 'unordered-list' , 'ordered-list ', '|' , 'link ' , 'image' , 'table' , 'horizontal-rule ', '|' , 'clean-block ' , '| ' ,
212- 'gitea-switch-to-textarea' ,
209+ 'bold' , 'italic' , 'strikethrough' , '|' , 'heading-1' , 'heading-2' , 'heading-3' ,
210+ 'heading-bigger ' , 'heading-smaller ' , '|' , 'code ' , 'quote ' , '|' , 'gitea-checkbox-empty ',
211+ 'gitea-checkbox-checked ' , '|' , 'unordered-list ' , 'ordered-list ' , '|' , 'link ' , 'image ' ,
212+ 'table' , 'horizontal-rule' , '|' , ' gitea-switch-to-textarea',
213213 ] ;
214-
215- this . easyMDEToolbarActions = {
216- 'gitea-checkbox-empty' : {
217- action ( e ) {
218- const cm = e . codemirror ;
219- cm . replaceSelection ( `\n- [ ] ${ cm . getSelection ( ) } ` ) ;
220- cm . focus ( ) ;
221- } ,
222- icon : svg ( 'gitea-empty-checkbox' ) ,
223- title : 'Add Checkbox (empty)' ,
224- } ,
225- 'gitea-checkbox-checked' : {
226- action ( e ) {
227- const cm = e . codemirror ;
228- cm . replaceSelection ( `\n- [x] ${ cm . getSelection ( ) } ` ) ;
229- cm . focus ( ) ;
230- } ,
231- icon : svg ( 'octicon-checkbox' ) ,
232- title : 'Add Checkbox (checked)' ,
233- } ,
234- 'gitea-switch-to-textarea' : {
235- action : ( ) => {
236- this . userPreferredEditor = 'textarea' ;
237- this . switchToTextarea ( ) ;
238- } ,
239- icon : svg ( 'octicon-file' ) ,
240- title : 'Revert to simple textarea' ,
241- } ,
242- 'gitea-code-inline' : {
243- action ( e ) {
244- const cm = e . codemirror ;
245- const selection = cm . getSelection ( ) ;
246- cm . replaceSelection ( `\`${ selection } \`` ) ;
247- if ( ! selection ) {
248- const cursorPos = cm . getCursor ( ) ;
249- cm . setCursor ( cursorPos . line , cursorPos . ch - 1 ) ;
250- }
251- cm . focus ( ) ;
252- } ,
253- icon : svg ( 'octicon-chevron-right' ) ,
254- title : 'Add Inline Code' ,
255- }
256- } ;
257214 }
258215
259- parseEasyMDEToolbar ( actions ) {
216+ parseEasyMDEToolbar ( EasyMDE , actions ) {
217+ this . easyMDEToolbarActions = this . easyMDEToolbarActions || easyMDEToolbarActions ( EasyMDE , this ) ;
260218 const processed = [ ] ;
261219 for ( const action of actions ) {
262- if ( action . startsWith ( 'gitea-' ) ) {
263- const giteaAction = this . easyMDEToolbarActions [ action ] ;
264- if ( ! giteaAction ) throw new Error ( `Unknown EasyMDE toolbar action ${ action } ` ) ;
265- processed . push ( giteaAction ) ;
266- } else {
267- processed . push ( action ) ;
268- }
220+ const actionButton = this . easyMDEToolbarActions [ action ] ;
221+ if ( ! actionButton ) throw new Error ( `Unknown EasyMDE toolbar action ${ action } ` ) ;
222+ processed . push ( actionButton ) ;
269223 }
270224 return processed ;
271225 }
@@ -293,7 +247,7 @@ class ComboMarkdownEditor {
293247 nativeSpellcheck : true ,
294248 ...this . options . easyMDEOptions ,
295249 } ;
296- easyMDEOpt . toolbar = this . parseEasyMDEToolbar ( easyMDEOpt . toolbar ?? this . easyMDEToolbarDefault ) ;
250+ easyMDEOpt . toolbar = this . parseEasyMDEToolbar ( EasyMDE , easyMDEOpt . toolbar ?? this . easyMDEToolbarDefault ) ;
297251
298252 this . easyMDE = new EasyMDE ( easyMDEOpt ) ;
299253 this . easyMDE . codemirror . on ( 'change' , ( ...args ) => { this . options ?. onContentChanged ?. ( this , ...args ) } ) ;
0 commit comments