(e)
| 6488 | var lastDrop = 0; |
| 6489 | |
| 6490 | function onDrop(e) { |
| 6491 | var cm = this; |
| 6492 | clearDragCursor(cm); |
| 6493 | if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) |
| 6494 | { return } |
| 6495 | e_preventDefault(e); |
| 6496 | if (ie) { lastDrop = +new Date; } |
| 6497 | var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files; |
| 6498 | if (!pos || cm.isReadOnly()) { return } |
| 6499 | // Might be a file drop, in which case we simply extract the text |
| 6500 | // and insert it. |
| 6501 | if (files && files.length && window.FileReader && window.File) { |
| 6502 | var n = files.length, text = Array(n), read = 0; |
| 6503 | var markAsReadAndPasteIfAllFilesAreRead = function () { |
| 6504 | if (++read == n) { |
| 6505 | operation(cm, function () { |
| 6506 | pos = clipPos(cm.doc, pos); |
| 6507 | var change = {from: pos, to: pos, |
| 6508 | text: cm.doc.splitLines( |
| 6509 | text.filter(function (t) { return t != null; }).join(cm.doc.lineSeparator())), |
| 6510 | origin: "paste"}; |
| 6511 | makeChange(cm.doc, change); |
| 6512 | setSelectionReplaceHistory(cm.doc, simpleSelection(clipPos(cm.doc, pos), clipPos(cm.doc, changeEnd(change)))); |
| 6513 | })(); |
| 6514 | } |
| 6515 | }; |
| 6516 | var readTextFromFile = function (file, i) { |
| 6517 | if (cm.options.allowDropFileTypes && |
| 6518 | indexOf(cm.options.allowDropFileTypes, file.type) == -1) { |
| 6519 | markAsReadAndPasteIfAllFilesAreRead(); |
| 6520 | return |
| 6521 | } |
| 6522 | var reader = new FileReader; |
| 6523 | reader.onerror = function () { return markAsReadAndPasteIfAllFilesAreRead(); }; |
| 6524 | reader.onload = function () { |
| 6525 | var content = reader.result; |
| 6526 | if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) { |
| 6527 | markAsReadAndPasteIfAllFilesAreRead(); |
| 6528 | return |
| 6529 | } |
| 6530 | text[i] = content; |
| 6531 | markAsReadAndPasteIfAllFilesAreRead(); |
| 6532 | }; |
| 6533 | reader.readAsText(file); |
| 6534 | }; |
| 6535 | for (var i = 0; i < files.length; i++) { readTextFromFile(files[i], i); } |
| 6536 | } else { // Normal drop |
| 6537 | // Don't do a replace if the drop happened inside of the selected text. |
| 6538 | if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) { |
| 6539 | cm.state.draggingText(e); |
| 6540 | // Ensure the editor is re-focused |
| 6541 | setTimeout(function () { return cm.display.input.focus(); }, 20); |
| 6542 | return |
| 6543 | } |
| 6544 | try { |
| 6545 | var text$1 = e.dataTransfer.getData("Text"); |
| 6546 | if (text$1) { |
| 6547 | var selected; |
nothing calls this directly
no test coverage detected