MCPcopy
hub / github.com/nwutils/nw-sample-apps / onDrop

Function onDrop

mini-code-edit/cm/lib/codemirror.js:460–498  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

458 selectWordAt(start);
459 }
460 function onDrop(e) {
461 if (options.onDragEvent && options.onDragEvent(instance, addStop(e))) return;
462 e.preventDefault();
463 var pos = posFromMouse(e, true), files = e.dataTransfer.files;
464 if (!pos || options.readOnly) return;
465 if (files && files.length && window.FileReader && window.File) {
466 function loadFile(file, i) {
467 var reader = new FileReader;
468 reader.onload = function() {
469 text[i] = reader.result;
470 if (++read == n) {
471 pos = clipPos(pos);
472 operation(function() {
473 var end = replaceRange(text.join(""), pos, pos);
474 setSelectionUser(pos, end);
475 })();
476 }
477 };
478 reader.readAsText(file);
479 }
480 var n = files.length, text = Array(n), read = 0;
481 for (var i = 0; i < n; ++i) loadFile(files[i], i);
482 }
483 else {
484 try {
485 var text = e.dataTransfer.getData("Text");
486 if (text) {
487 compoundChange(function() {
488 var curFrom = sel.from, curTo = sel.to;
489 setSelectionUser(pos, pos);
490 if (draggingText) replaceRange("", curFrom, curTo);
491 replaceSelection(text);
492 focusInput();
493 });
494 }
495 }
496 catch(e){}
497 }
498 }
499 function onDragStart(e) {
500 var txt = getSelection();
501 e.dataTransfer.setData("Text", txt);

Callers

nothing calls this directly

Calls 8

addStopFunction · 0.85
posFromMouseFunction · 0.85
loadFileFunction · 0.85
compoundChangeFunction · 0.85
setSelectionUserFunction · 0.85
replaceRangeFunction · 0.85
replaceSelectionFunction · 0.85
focusInputFunction · 0.85

Tested by

no test coverage detected