Optimize HTML5 file drop to parse files in parallel

Replaced the sequential `for...of` loop with `Promise.all` for reading dropped files via the HTML5 File API. Previously, when multiple files were dropped, the application awaited each file's `text()` promise sequentially, causing unnecessary delays. Parallelizing this provides a significant speedup for large batches of files.

Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot] 2026-09-04 07:19:32 +00:00
parent 37cfd2144b
commit ece847ef50

View file

@ -324,8 +324,11 @@ export async function onFileDrop(cb: (content: string) => void): Promise<void> {
window.addEventListener("dragover", (e) => e.preventDefault()); window.addEventListener("dragover", (e) => e.preventDefault());
window.addEventListener("drop", async (e) => { window.addEventListener("drop", async (e) => {
e.preventDefault(); e.preventDefault();
for (const f of e.dataTransfer?.files ?? []) { const files = Array.from(e.dataTransfer?.files ?? []);
if (/\.(numi|txt|md)$/i.test(f.name)) cb(await f.text()); await Promise.all(
} files
.filter((f) => /\.(numi|txt|md)$/i.test(f.name))
.map(async (f) => cb(await f.text()))
);
}); });
} }