Skip to content

Commit 493d802

Browse files
committed
Attachments: Fixed drag into editor in Chrome
Seemed to be chrome specific from testing. Required editors to have preventDefault called on dragover. Tested in Chrome, FF, & Safari. Tested in both editors, and re-tested text/image drop to ensure still works. Fixed #4975
1 parent 06bb551 commit 493d802

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

resources/js/markdown/codemirror.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export async function init(editor) {
4444
editor.actions.insertClipboardImages(clipboardImages, event.pageX, event.pageY);
4545
}
4646
},
47+
// Handle dragover event to allow as drop-target in chrome
48+
dragover: event => {
49+
event.preventDefault();
50+
},
4751
// Handle image paste
4852
paste: event => {
4953
const clipboard = new Clipboard(event.clipboardData || event.dataTransfer);

resources/js/wysiwyg/drop-paste-handling.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,26 @@ function drop(editor, options, event) {
149149
wrap = null;
150150
}
151151

152+
/**
153+
* @param {Editor} editor
154+
* @param {DragEvent} event
155+
*/
156+
function dragOver(editor, event) {
157+
// This custom handling essentially emulates the default TinyMCE behaviour while allowing us
158+
// to specifically call preventDefault on the event to allow the drop of custom elements.
159+
event.preventDefault();
160+
editor.focus();
161+
const rangeUtils = window.tinymce.dom.RangeUtils;
162+
const range = rangeUtils.getCaretRangeFromPoint(event.clientX ?? 0, event.clientY ?? 0, editor.getDoc());
163+
editor.selection.setRng(range);
164+
}
165+
152166
/**
153167
* @param {Editor} editor
154168
* @param {WysiwygConfigOptions} options
155169
*/
156170
export function listenForDragAndPaste(editor, options) {
171+
editor.on('dragover', event => dragOver(editor, event));
157172
editor.on('dragstart', () => dragStart(editor));
158173
editor.on('drop', event => drop(editor, options, event));
159174
editor.on('paste', event => paste(editor, options, event));

0 commit comments

Comments
 (0)