mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 03:41:30 +01:00
1a7473ff45
* split `index.js` to separate files * tune clipboard * fix promise * fix document * remove intermediate empty file * fix async event listener * use `export function` instead of `export {}`, add more comments Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de>
72 lines
2.1 KiB
JavaScript
72 lines
2.1 KiB
JavaScript
import attachTribute from '../tribute.js';
|
|
|
|
export function createCommentSimpleMDE($editArea) {
|
|
if ($editArea.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
const simplemde = new SimpleMDE({
|
|
autoDownloadFontAwesome: false,
|
|
element: $editArea[0],
|
|
forceSync: true,
|
|
renderingConfig: {
|
|
singleLineBreaks: false
|
|
},
|
|
indentWithTabs: false,
|
|
tabSize: 4,
|
|
spellChecker: false,
|
|
toolbar: ['bold', 'italic', 'strikethrough', '|',
|
|
'heading-1', 'heading-2', 'heading-3', 'heading-bigger', 'heading-smaller', '|',
|
|
'code', 'quote', '|', {
|
|
name: 'checkbox-empty',
|
|
action(e) {
|
|
const cm = e.codemirror;
|
|
cm.replaceSelection(`\n- [ ] ${cm.getSelection()}`);
|
|
cm.focus();
|
|
},
|
|
className: 'fa fa-square-o',
|
|
title: 'Add Checkbox (empty)',
|
|
},
|
|
{
|
|
name: 'checkbox-checked',
|
|
action(e) {
|
|
const cm = e.codemirror;
|
|
cm.replaceSelection(`\n- [x] ${cm.getSelection()}`);
|
|
cm.focus();
|
|
},
|
|
className: 'fa fa-check-square-o',
|
|
title: 'Add Checkbox (checked)',
|
|
}, '|',
|
|
'unordered-list', 'ordered-list', '|',
|
|
'link', 'image', 'table', 'horizontal-rule', '|',
|
|
'clean-block', '|',
|
|
{
|
|
name: 'revert-to-textarea',
|
|
action(e) {
|
|
e.toTextArea();
|
|
},
|
|
className: 'fa fa-file',
|
|
title: 'Revert to simple textarea',
|
|
},
|
|
]
|
|
});
|
|
$(simplemde.codemirror.getInputField()).addClass('js-quick-submit');
|
|
simplemde.codemirror.setOption('extraKeys', {
|
|
Enter: () => {
|
|
const tributeContainer = document.querySelector('.tribute-container');
|
|
if (!tributeContainer || tributeContainer.style.display === 'none') {
|
|
return CodeMirror.Pass;
|
|
}
|
|
},
|
|
Backspace: (cm) => {
|
|
if (cm.getInputField().trigger) {
|
|
cm.getInputField().trigger('input');
|
|
}
|
|
cm.execCommand('delCharBefore');
|
|
}
|
|
});
|
|
attachTribute(simplemde.codemirror.getInputField(), {mentions: true, emoji: true});
|
|
$editArea.data('simplemde', simplemde);
|
|
$(simplemde.codemirror.getInputField()).data('simplemde', simplemde);
|
|
return simplemde;
|
|
}
|