forked from forgejo/forgejo
Support markdown editor for issue template (#24400)
Fixes #24398 Task: - [x] Reusing "textarea" like GitHub seems more friendly to users. - [x] ^V image pasting and file uploading handling. <details><summary>screenshots</summary>   Display only one markdown editor:  Support file upload and ^V image pasting  </details> --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
parent
9ad5b59cd9
commit
c4303efc23
8 changed files with 176 additions and 89 deletions
|
@ -665,3 +665,59 @@ export function initRepoIssueGotoID() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function initSingleCommentEditor($commentForm) {
|
||||
// pages:
|
||||
// * normal new issue/pr page, no status-button
|
||||
// * issue/pr view page, with comment form, has status-button
|
||||
const opts = {};
|
||||
const $statusButton = $('#status-button');
|
||||
if ($statusButton.length) {
|
||||
$statusButton.on('click', (e) => {
|
||||
e.preventDefault();
|
||||
$('#status').val($statusButton.data('status-val'));
|
||||
$('#comment-form').trigger('submit');
|
||||
});
|
||||
opts.onContentChanged = (editor) => {
|
||||
$statusButton.text($statusButton.attr(editor.value().trim() ? 'data-status-and-comment' : 'data-status'));
|
||||
};
|
||||
}
|
||||
initComboMarkdownEditor($commentForm.find('.combo-markdown-editor'), opts);
|
||||
}
|
||||
|
||||
export function initIssueTemplateCommentEditors($commentForm) {
|
||||
// pages:
|
||||
// * new issue with issue template
|
||||
const $comboFields = $commentForm.find('.combo-editor-dropzone');
|
||||
|
||||
const initCombo = async ($combo) => {
|
||||
const $dropzoneContainer = $combo.find('.form-field-dropzone');
|
||||
const $formField = $combo.find('.form-field-real');
|
||||
const $markdownEditor = $combo.find('.combo-markdown-editor');
|
||||
|
||||
const editor = await initComboMarkdownEditor($markdownEditor, {
|
||||
onContentChanged: (editor) => {
|
||||
$formField.val(editor.value());
|
||||
}
|
||||
});
|
||||
|
||||
$formField.on('focus', async () => {
|
||||
// deactivate all markdown editors
|
||||
showElem($commentForm.find('.combo-editor-dropzone .form-field-real'));
|
||||
hideElem($commentForm.find('.combo-editor-dropzone .combo-markdown-editor'));
|
||||
hideElem($commentForm.find('.combo-editor-dropzone .form-field-dropzone'));
|
||||
|
||||
// activate this markdown editor
|
||||
hideElem($formField);
|
||||
showElem($markdownEditor);
|
||||
showElem($dropzoneContainer);
|
||||
|
||||
await editor.switchToUserPreference();
|
||||
editor.focus();
|
||||
});
|
||||
};
|
||||
|
||||
for (const el of $comboFields) {
|
||||
initCombo($(el));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue