1
0
Fork 0
forked from forgejo/forgejo

Load EasyMDE/CodeMirror dynamically, remove RequireEasyMDE (#18069)

This PR makes frontend load EasyMDE/CodeMirror dynamically, and removes `RequireEasyMDE`.
This commit is contained in:
wxiaoguang 2022-01-05 20:17:25 +08:00 committed by GitHub
parent 0572c78938
commit a38ba634a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 239 additions and 223 deletions

View file

@ -1,6 +1,6 @@
import {htmlEscape} from 'escape-goat';
import attachTribute from './tribute.js';
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/CommentEasyMDE.js';
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js';
import {initCompImagePaste} from './comp/ImagePaste.js';
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
@ -439,16 +439,17 @@ export function initRepoPullRequestReview() {
$(`#show-outdated-${id}`).removeClass('hide');
});
$(document).on('click', 'button.comment-form-reply', function (e) {
$(document).on('click', 'button.comment-form-reply', async function (e) {
e.preventDefault();
$(this).hide();
const form = $(this).closest('.comment-code-cloud').find('.comment-form');
form.removeClass('hide');
const $textarea = form.find('textarea');
let easyMDE = getAttachedEasyMDE($textarea);
if (!easyMDE) {
attachTribute($textarea.get(), {mentions: true, emoji: true});
easyMDE = createCommentEasyMDE($textarea);
await attachTribute($textarea.get(), {mentions: true, emoji: true});
easyMDE = await createCommentEasyMDE($textarea);
}
$textarea.focus();
easyMDE.codemirror.focus();
@ -515,8 +516,8 @@ export function initRepoPullRequestReview() {
td.find("input[name='side']").val(side === 'left' ? 'previous' : 'proposed');
td.find("input[name='path']").val(path);
const $textarea = commentCloud.find('textarea');
attachTribute($textarea.get(), {mentions: true, emoji: true});
const easyMDE = createCommentEasyMDE($textarea);
await attachTribute($textarea.get(), {mentions: true, emoji: true});
const easyMDE = await createCommentEasyMDE($textarea);
$textarea.focus();
easyMDE.codemirror.focus();
}