MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / onDrop

Function onDrop

static/js/codemirror/codemirror.js:1662–1704  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

1660 }
1661
1662 function onDrop(e) {
1663 var cm = this;
1664 if (eventInWidget(cm.display, e) || (cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))))
1665 return;
1666 e_preventDefault(e);
1667 var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
1668 if (!pos || isReadOnly(cm)) return;
1669 if (files && files.length && window.FileReader && window.File) {
1670 var n = files.length, text = Array(n), read = 0;
1671 var loadFile = function(file, i) {
1672 var reader = new FileReader;
1673 reader.onload = function() {
1674 text[i] = reader.result;
1675 if (++read == n) {
1676 pos = clipPos(cm.doc, pos);
1677 replaceRange(cm.doc, text.join(""), pos, "around", "paste");
1678 }
1679 };
1680 reader.readAsText(file);
1681 };
1682 for (var i = 0; i < n; ++i) loadFile(files[i], i);
1683 } else {
1684 // Don't do a replace if the drop happened inside of the selected text.
1685 if (cm.state.draggingText && !(posLess(pos, cm.doc.sel.from) || posLess(cm.doc.sel.to, pos))) {
1686 cm.state.draggingText(e);
1687 // Ensure the editor is re-focused
1688 setTimeout(bind(focusInput, cm), 20);
1689 return;
1690 }
1691 try {
1692 var text = e.dataTransfer.getData("Text");
1693 if (text) {
1694 var curFrom = cm.doc.sel.from, curTo = cm.doc.sel.to;
1695 setSelection(cm.doc, pos, pos);
1696 if (cm.state.draggingText) replaceRange(cm.doc, "", curFrom, curTo, "paste");
1697 cm.replaceSelection(text, null, "paste");
1698 focusInput(cm);
1699 onFocus(cm);
1700 }
1701 }
1702 catch(e){}
1703 }
1704 }
1705
1706 function clickInGutter(cm, e) {
1707 var display = cm.display;

Callers

nothing calls this directly

Calls 12

eventInWidgetFunction · 0.85
addStopFunction · 0.85
e_preventDefaultFunction · 0.85
posFromMouseFunction · 0.85
isReadOnlyFunction · 0.85
loadFileFunction · 0.85
posLessFunction · 0.85
bindFunction · 0.85
setSelectionFunction · 0.85
replaceRangeFunction · 0.85
focusInputFunction · 0.85
onFocusFunction · 0.70

Tested by

no test coverage detected