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
|
@ -25,6 +25,10 @@ function clipboardPastedImages(e) {
|
|||
return files;
|
||||
}
|
||||
|
||||
function triggerEditorContentChanged(target) {
|
||||
target.dispatchEvent(new CustomEvent('ce-editor-content-changed', {bubbles: true}));
|
||||
}
|
||||
|
||||
class TextareaEditor {
|
||||
constructor(editor) {
|
||||
this.editor = editor;
|
||||
|
@ -38,6 +42,7 @@ class TextareaEditor {
|
|||
editor.selectionStart = startPos;
|
||||
editor.selectionEnd = startPos + value.length;
|
||||
editor.focus();
|
||||
triggerEditorContentChanged(editor);
|
||||
}
|
||||
|
||||
replacePlaceholder(oldVal, newVal) {
|
||||
|
@ -54,6 +59,7 @@ class TextareaEditor {
|
|||
}
|
||||
editor.selectionStart = editor.selectionEnd;
|
||||
editor.focus();
|
||||
triggerEditorContentChanged(editor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +76,7 @@ class CodeMirrorEditor {
|
|||
endPoint.ch = startPoint.ch + value.length;
|
||||
editor.setSelection(startPoint, endPoint);
|
||||
editor.focus();
|
||||
triggerEditorContentChanged(editor.getTextArea());
|
||||
}
|
||||
|
||||
replacePlaceholder(oldVal, newVal) {
|
||||
|
@ -84,6 +91,7 @@ class CodeMirrorEditor {
|
|||
endPoint.ch += newVal.length;
|
||||
editor.setSelection(endPoint, endPoint);
|
||||
editor.focus();
|
||||
triggerEditorContentChanged(editor.getTextArea());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue