(e)
| 2746 | var lastDrop = 0; |
| 2747 | |
| 2748 | function onDrop(e) { |
| 2749 | var cm = this; |
| 2750 | if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) |
| 2751 | return; |
| 2752 | e_preventDefault(e); |
| 2753 | if (ie_upto10) lastDrop = +new Date; |
| 2754 | var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files; |
| 2755 | if (!pos || isReadOnly(cm)) return; |
| 2756 | // Might be a file drop, in which case we simply extract the text |
| 2757 | // and insert it. |
| 2758 | if (files && files.length && window.FileReader && window.File) { |
| 2759 | var n = files.length, text = Array(n), read = 0; |
| 2760 | var loadFile = function(file, i) { |
| 2761 | var reader = new FileReader; |
| 2762 | reader.onload = operation(cm, function() { |
| 2763 | text[i] = reader.result; |
| 2764 | if (++read == n) { |
| 2765 | pos = clipPos(cm.doc, pos); |
| 2766 | var change = {from: pos, to: pos, text: splitLines(text.join("\n")), origin: "paste"}; |
| 2767 | makeChange(cm.doc, change); |
| 2768 | setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change))); |
| 2769 | } |
| 2770 | }); |
| 2771 | reader.readAsText(file); |
| 2772 | }; |
| 2773 | for (var i = 0; i < n; ++i) loadFile(files[i], i); |
| 2774 | } else { // Normal drop |
| 2775 | // Don't do a replace if the drop happened inside of the selected text. |
| 2776 | if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) { |
| 2777 | cm.state.draggingText(e); |
| 2778 | // Ensure the editor is re-focused |
| 2779 | setTimeout(bind(focusInput, cm), 20); |
| 2780 | return; |
| 2781 | } |
| 2782 | try { |
| 2783 | var text = e.dataTransfer.getData("Text"); |
| 2784 | if (text) { |
| 2785 | var selected = cm.state.draggingText && cm.listSelections(); |
| 2786 | setSelectionNoUndo(cm.doc, simpleSelection(pos, pos)); |
| 2787 | if (selected) for (var i = 0; i < selected.length; ++i) |
| 2788 | replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag"); |
| 2789 | cm.replaceSelection(text, "around", "paste"); |
| 2790 | focusInput(cm); |
| 2791 | } |
| 2792 | } |
| 2793 | catch(e){} |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | function onDragStart(cm, e) { |
| 2798 | if (ie_upto10 && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return; } |
nothing calls this directly
no test coverage detected