From 2bd72809d4fc94d2888a485ac625fc4f350a00f8 Mon Sep 17 00:00:00 2001 From: nanami Date: Mon, 21 Sep 2026 02:14:46 +0800 Subject: [PATCH] fix(editor): never save a truncated read over the full file (#732) A text load truncated at readLimit only carries the file's first bytes, but the editor still offered editing and saving on it: fs.write replaces the whole file, so one Ctrl+S on a >512KB file silently destroyed everything past the limit. - render truncated documents read-only (EditorState.readOnly) - guard save() against the truncated keymap path - report `truncated` in EditorToolbarState and hide the save buttons (host header + the editor's own toolbar) while it is set - show the truncation banner in preview mode too, so the read-only state is explained before any edit attempt --- src/client/EditorHost.tsx | 2 +- src/client/TextEditor.tsx | 18 ++++++-- src/client/service.ts | 4 ++ tests/editor-host.spec.tsx | 42 +++++++++++++++++++ tests/editor-truncated-save.spec.tsx | 63 ++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 tests/editor-truncated-save.spec.tsx diff --git a/src/client/EditorHost.tsx b/src/client/EditorHost.tsx index 21817398..2fb9084b 100644 --- a/src/client/EditorHost.tsx +++ b/src/client/EditorHost.tsx @@ -439,7 +439,7 @@ export function EditorHost(props: { )} {toolbar?.dirty === true && } - {toolbar?.editable === true && ( + {toolbar?.editable === true && toolbar?.truncated !== true && (