ElyTable: a large text file no longer freezes the window before its import dialog (T-09)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 18:42:39 -04:00
1 parent 0c87b0bbf7
commit 6145b5cea2
3 files changed
+11 -7

No files matched your search

+9 -6
View File
@@ -235,13 +235,16 @@ impl Book {
let reading = path.clone();
let chinese = ely_ui::i18n::resolve(&ely_platform::locale::system()) == "zh-CN";
cx.spawn(async move |this, cx| {
let bytes = cx
.background_spawn(async move { std::fs::read(&reading) })
// Guessing checks the whole file: off the window thread.
let pending = cx
.background_spawn(async move {
std::fs::read(&reading).map(|bytes| Pending::new(reading, bytes, chinese))
})
.await;
in_window(&this, cx, |book, _, cx| match bytes {
Ok(bytes) => {
log::info!("table: import asks for {} bytes", bytes.len());
book.imports.push_back(Pending::new(path, bytes, chinese));
in_window(&this, cx, |book, _, cx| match pending {
Ok(pending) => {
log::info!("table: import asks for {} bytes", pending.bytes.len());
book.imports.push_back(pending);
book.next_import(cx);
}
Err(error) => book.failed_open(&path.display().to_string(), &error, cx),