MCPcopy
hub / github.com/witheve/Eve / loadFile

Function loadFile

src/codemirror.js:3874–3894  ·  view source on GitHub ↗
(file, i)

Source from the content-addressed store, hash-verified

3872 if (files && files.length && window.FileReader && window.File) {
3873 var n = files.length, text = Array(n), read = 0;
3874 var loadFile = function(file, i) {
3875 if (cm.options.allowDropFileTypes &&
3876 indexOf(cm.options.allowDropFileTypes, file.type) == -1)
3877 return;
3878
3879 var reader = new FileReader;
3880 reader.onload = operation(cm, function() {
3881 var content = reader.result;
3882 if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) content = "";
3883 text[i] = content;
3884 if (++read == n) {
3885 pos = clipPos(cm.doc, pos);
3886 var change = {from: pos, to: pos,
3887 text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
3888 origin: "paste"};
3889 makeChange(cm.doc, change);
3890 setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
3891 }
3892 });
3893 reader.readAsText(file);
3894 };
3895 for (var i = 0; i < n; ++i) loadFile(files[i], i);
3896 } else { // Normal drop
3897 // Don't do a replace if the drop happened inside of the selected text.

Callers 1

onDropFunction · 0.85

Calls 7

indexOfFunction · 0.85
operationFunction · 0.85
clipPosFunction · 0.85
makeChangeFunction · 0.85
simpleSelectionFunction · 0.85
testMethod · 0.45

Tested by

no test coverage detected