Zixuan19 commited on
Commit
68f0f6a
·
verified ·
1 Parent(s): 46e4580

fix: files after a text file were dropped on multi-select; short text flagged at upload

Browse files
Files changed (1) hide show
  1. app.js +5 -3
app.js CHANGED
@@ -465,7 +465,9 @@ async function main() {
465
  if (!k) { bad.push(msg("file_type", {x: f.name})); continue; }
466
  if (f.size > M[k]) { bad.push(msg("file_big", {x: f.name, s: f.size / 1e6, c: M[k] / 1e6})); continue; }
467
  if (files.length >= M.files) { bad.push(msg("max_files", {m: M.files, n: files.length + 1})); break; }
468
- if (k === "text") f._paras = splitParas(await f.text()); else f._url = URL.createObjectURL(f);
 
 
469
  files.push(f); }
470
  $("#file_msg").innerHTML = bad.map(esc).join("<br>"); refreshRefs(); stale(); };
471
  $("#link").addEventListener("input", () => $$(".point").forEach(renderPicks));
@@ -480,10 +482,10 @@ async function main() {
480
  $("#form").addEventListener("mouseover", e => { const b = e.target.closest(".imgtile"); if (!b) { peek.hidden = true; return; }
481
  const r = b.getBoundingClientRect(); peek.src = $("img", b).src; peek.style.left = Math.max(8, Math.min(r.left, innerWidth - 350)) + "px"; peek.style.top = (r.top - 8) + "px"; peek.hidden = false; });
482
  $("#form").addEventListener("mouseleave", () => { peek.hidden = true; });
483
- $("#file").onchange = e => { add(e.target.files); e.target.value = ""; };
484
  const drop = $("#drop");
485
  drop.ondragover = e => { e.preventDefault(); drop.classList.add("over"); }; drop.ondragleave = () => drop.classList.remove("over");
486
- drop.ondrop = e => { e.preventDefault(); drop.classList.remove("over"); add(e.dataTransfer.files); };
487
  $("#form").addEventListener("input", () => { stale(); counters(); });
488
  $("#form").addEventListener("change", stale);
489
  const nav = $$("#steps a"), secs = nav.map(a => $(a.getAttribute("href"))); // highlight the section being read
 
465
  if (!k) { bad.push(msg("file_type", {x: f.name})); continue; }
466
  if (f.size > M[k]) { bad.push(msg("file_big", {x: f.name, s: f.size / 1e6, c: M[k] / 1e6})); continue; }
467
  if (files.length >= M.files) { bad.push(msg("max_files", {m: M.files, n: files.length + 1})); break; }
468
+ if (k === "text") { const text = await f.text(), n = size(text), m = Math.floor(D.limits.text_units * D.scale[lang]); f._paras = splitParas(text);
469
+ if (n < m) bad.push(msg("short_text", {x: f.name, n, m})); } // kept, but said at once: it will not pass the check
470
+ else f._url = URL.createObjectURL(f);
471
  files.push(f); }
472
  $("#file_msg").innerHTML = bad.map(esc).join("<br>"); refreshRefs(); stale(); };
473
  $("#link").addEventListener("input", () => $$(".point").forEach(renderPicks));
 
482
  $("#form").addEventListener("mouseover", e => { const b = e.target.closest(".imgtile"); if (!b) { peek.hidden = true; return; }
483
  const r = b.getBoundingClientRect(); peek.src = $("img", b).src; peek.style.left = Math.max(8, Math.min(r.left, innerWidth - 350)) + "px"; peek.style.top = (r.top - 8) + "px"; peek.hidden = false; });
484
  $("#form").addEventListener("mouseleave", () => { peek.hidden = true; });
485
+ $("#file").onchange = e => { add([...e.target.files]); e.target.value = ""; }; // a copy: the list empties when the input is cleared
486
  const drop = $("#drop");
487
  drop.ondragover = e => { e.preventDefault(); drop.classList.add("over"); }; drop.ondragleave = () => drop.classList.remove("over");
488
+ drop.ondrop = e => { e.preventDefault(); drop.classList.remove("over"); add([...e.dataTransfer.files]); };
489
  $("#form").addEventListener("input", () => { stale(); counters(); });
490
  $("#form").addEventListener("change", stale);
491
  const nav = $$("#steps a"), secs = nav.map(a => $(a.getAttribute("href"))); // highlight the section being read