From fd6e65147835bfbc599e4fc4fffcafde191f6a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Fri, 9 Oct 2026 19:56:59 -0400 Subject: [PATCH] ElyTable: a text file's default encoding follows the app's language (T-15) --- apps/ely-table/src/tests/output.rs | 29 +++++++++++++++++++++++++++++ apps/ely-table/src/text.rs | 3 ++- tasks/BUGS.md | 2 +- tasks/reviews/T-15-r1.md | 1 + 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tasks/reviews/T-15-r1.md diff --git a/apps/ely-table/src/tests/output.rs b/apps/ely-table/src/tests/output.rs index 8ae2d00..769da9f 100644 --- a/apps/ely-table/src/tests/output.rs +++ b/apps/ely-table/src/tests/output.rs @@ -469,3 +469,32 @@ fn a_whole_column_print_area_still_applies() { let layout = read(&mut cx, &book, sheet::print_layout, sheet::LAYOUT); assert!(layout.landscape, "applied with {shown}"); } + +#[test] +fn the_default_encoding_follows_the_apps_language() { + use ely_gpui_component::i18n::I18n; + use ely_lok::sheet::csv::Encoding; + let dir = tempfile::tempdir().expect("a temp dir"); + let mut cx = TestAppContext::single(); + let Some((_window, book)) = book(&mut cx, dir.path()) else { + eprintln!("SKIP: no LOK build"); + return; + }; + let path = dir.path().join("gb.csv"); + // 你好 in GB18030: not UTF-8. + std::fs::write(&path, [0xC4, 0xE3, 0xBA, 0xC3, b'\n']).expect("writes"); + for (tag, expected) in [("zh-CN", Encoding::Gb18030), ("en-US", Encoding::Windows1252)] { + cx.update(|app| I18n::set_locale(tag, app)); + update(&mut cx, &book, |book, cx| book.ask_import(path.clone(), cx)); + asked(&cx, &book, |dialog| matches!(dialog, Dialog::Import(_))); + let found = cx.update(|app| match book.read(app).dialog.as_ref() { + Some(Dialog::Import(pending)) => pending.how.encoding, + _ => unreachable!("an import dialog"), + }); + assert_eq!(found, expected, "{tag}"); + update(&mut cx, &book, |book, cx| { + book.dialog = None; + cx.notify(); + }); + } +} diff --git a/apps/ely-table/src/text.rs b/apps/ely-table/src/text.rs index 534e8db..5ab4edf 100644 --- a/apps/ely-table/src/text.rs +++ b/apps/ely-table/src/text.rs @@ -231,7 +231,8 @@ impl Book { pub(crate) fn ask_import(&mut self, path: PathBuf, cx: &mut Context) { let reading = path.clone(); - let chinese = ely_ui::i18n::resolve(&ely_platform::locale::system()) == "zh-CN"; + // The language the app shows, not the system's. + let chinese = cx.global::().locale().tag == "zh-CN"; cx.spawn(async move |this, cx| { // Guessing checks the whole file: off the window thread. let pending = cx diff --git a/tasks/BUGS.md b/tasks/BUGS.md index 4e05cff..5fc9b06 100644 --- a/tasks/BUGS.md +++ b/tasks/BUGS.md @@ -22,7 +22,7 @@ - [x] T-12 打印区域是整列或整行时页面设置无法应用 — 打印区域可为整列、整行(每端至多一个 $);R2 PASS - [x] T-13 打印失败报成“导出失败”(非 macOS 必现) — print_later 自己以“打印失败”报错,五个应用同;R1 PASS - [x] T-14 导入扫描把整个文件的每个字段都建成字符串 — split 逐行给出,扫描只留预览行与列标记;R1 PASS -- [ ] T-15 非 UTF-8 文本的默认编码跟系统区域而不是界面语言 +- [x] T-15 非 UTF-8 文本的默认编码跟系统区域而不是界面语言 — 默认编码按应用所显示的语言;R1 PASS - [x] S-01 切换幻灯片后主画布不重画 — 已由 be31260(R2.4)修好并有单测,此处补勾 - [x] S-02 `deck.rs` 超过 500 行 — 随 S-03 把 Extra 移到 extra.rs,deck.rs 463 行 - [x] S-03 ElyShow 的缩放一两帧后弹回“适合幻灯片”,缩放功能不可用 — 只在标签首次观察时适合一次;R1 PASS diff --git a/tasks/reviews/T-15-r1.md b/tasks/reviews/T-15-r1.md new file mode 100644 index 0000000..7ef22e9 --- /dev/null +++ b/tasks/reviews/T-15-r1.md @@ -0,0 +1 @@ +PASS