fix(persistence): show a saved note's trailing newline as an empty line
Read notes verbatim and insert the final newline only when it is missing,
instead of stripping the terminator on load and appending it unconditionally
on save. The editor's `rows = #\n + 1` model then renders a file's POSIX
terminator as a visible trailing blank line — what a writer expects: open a
note and see (and land the caret on) the empty line the newline stands for.
Supersedes the strip-on-load / unconditional-append handling that shipped
with the prefs work (c535864), which kept the buffer newline-free and hid the
terminator. Load + save are now an identity round-trip for any device-written
file (all end in '\n'); files stay git-clean (exactly one terminator); and a
trailing blank line the writer leaves is mirrored, never doubled.
- load_path: read verbatim (drop the strip)
- save_path: guarded final-newline (drop the unconditional append)
- Prefs::to_toml: ends in a newline again — the guarded save leaves exactly
one, so the prefs file is byte-identical to before and its device-verified
round-trip still holds
- sd_fat spike: payload ends in '\n' so its exact-equality round-trip holds
This commit is contained in:
@@ -239,10 +239,9 @@ impl Prefs {
|
||||
}
|
||||
|
||||
/// Serialize back to the [`PREFS_PATH`] form, with a header comment pointing at
|
||||
/// both edit paths. Round-trips with [`parse`](Prefs::parse). Emitted *without*
|
||||
/// a trailing newline: like the editor buffer, this is content without its
|
||||
/// terminator — the persistence layer appends the single POSIX newline on write
|
||||
/// (and strips it back on read), so returning one here would double it.
|
||||
/// both edit paths. Round-trips with [`parse`](Prefs::parse). Ends in a newline
|
||||
/// like a normal text file; `save_path`'s guarded final-newline write leaves it
|
||||
/// as exactly one.
|
||||
pub fn to_toml(&self) -> String {
|
||||
format!(
|
||||
"# Typoena editor preferences — hand-editable, git-tracked.\n\
|
||||
@@ -250,7 +249,7 @@ impl Prefs {
|
||||
save_on_idle = {}\n\
|
||||
format_on_save = {}\n\
|
||||
line_numbers = {}\n\
|
||||
auto_sync = \"{}\"",
|
||||
auto_sync = \"{}\"\n",
|
||||
self.save_on_idle, self.format_on_save, self.line_numbers, self.auto_sync,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user