import $ from 'jquery';
import {attachTribute} from '../tribute.ts';
import {hideElem, showElem, autosize, isElemVisible} from '../../utils/dom.ts';
-import {initEasyMDEPaste, initTextareaUpload} from './EditorUpload.ts';
+import {initEasyMDEPaste, initTextareaEvents} from './EditorUpload.ts';
import {handleGlobalEnterQuickSubmit} from './QuickSubmit.ts';
import {renderPreviewPanelContent} from '../repo-editor.ts';
import {easyMDEToolbarActions} from './EasyMDEToolbarActions.ts';
});
initTextareaMarkdown(this.textarea);
- if (this.dropzone) {
- initTextareaUpload(this.textarea, this.dropzone);
- }
+ initTextareaEvents(this.textarea, this.dropzone);
}
async setupDropzone() {
const {value, selectionStart, selectionEnd} = textarea;
const selectedText = value.substring(selectionStart, selectionEnd);
const trimmedText = text.trim();
- if (selectedText && isUrl(trimmedText)) {
+ if (selectedText && isUrl(trimmedText) && !isUrl(selectedText)) {
e.preventDefault();
replaceTextareaSelection(textarea, `[${selectedText}](${trimmedText})`);
}
});
}
-export function initTextareaUpload(textarea, dropzoneEl) {
+export function initTextareaEvents(textarea, dropzoneEl) {
let isShiftDown = false;
textarea.addEventListener('keydown', (e) => {
if (e.shiftKey) isShiftDown = true;
});
textarea.addEventListener('paste', (e) => {
const {images, text} = getPastedContent(e);
- if (images.length) {
+ if (images.length && dropzoneEl) {
handleUploadFiles(new TextareaEditor(textarea), dropzoneEl, images, e);
} else if (text) {
handleClipboardText(textarea, e, {text, isShiftDown});
if (!e.dataTransfer.files.length) return;
handleUploadFiles(new TextareaEditor(textarea), dropzoneEl, e.dataTransfer.files, e);
});
- dropzoneEl.dropzone.on(DropzoneCustomEventRemovedFile, ({fileUuid}) => {
+ dropzoneEl?.dropzone.on(DropzoneCustomEventRemovedFile, ({fileUuid}) => {
const newText = removeAttachmentLinksFromMarkdown(textarea.value, fileUuid);
if (textarea.value !== newText) textarea.value = newText;
});