Skip to content

zn v0.15.0: undo cannot wipe a note, autosave can be off, gd follows links like the desktop - #32

Merged
adibhanna merged 4 commits into
mainfrom
claude/fix-autosave-undo-gd-b13126
Nov 3, 2026
Merged

adibhanna merged 4 commits into
mainfrom
claude/fix-autosave-undo-gd-b13126

Conversation

@adibhanna

Copy link
Copy Markdown
Contributor

Three fixes from a user report about zn tui. The first one lost data.

Undo could wipe a note

A note opened by a key press starts as an empty editor, and its text arrived as an undoable change. Pressing u right after opening went back to empty, and autosave then wrote that over the file.

  • The first successful read now replaces the placeholder outside the history (Editor.LoadText), so undo stops at the note as opened. This also holds when the first read failed and a later one worked.
  • A note that started empty can still undo to empty. If undo or redo leaves a buffer blank while its file has text, autosave, closing a tab and quitting no longer write it. :w, Ctrl+S and :wq still can, and ggdG is an edit that saves as ever.

Autosave can be turned off

There was no such setting, so every key was ignored. [terminal] autosave = false is new, and also works through zn config set terminal.autosave false and :settings. The default stays on.

With autosave off Result
:w, Ctrl+S, :wq, :wa, :wqa Save
:q, :qa, Ctrl+C, closing the last tab showing the note, switching vault Refused while there are unsaved edits
:q!, :qa! Discard the edits
Any other exit, such as the terminal closing Edits go to a recovery copy, not the note
Rename, move, trash, task toggle, $EDITOR Still save first, because they act on the file

gd on a link with no .md

[[2020-03-31](./Daily/2020-03-31)] gave "Not a note". The new vault.ResolveNoteHref ports the desktop's resolveInternalNoteHref: relative to the current note, tolerant of a missing extension and percent-encoding, followed by a wikilink lookup.

Behavior change to check in review: a relative path now beats the same path from the vault root. That matches the desktop and differs from the old TUI order.

Testing

  • go test ./... passes on macOS. New tests cover each behavior, and each fix's tests were checked to fail with that fix reverted.
  • Each bug was reproduced on the old binary, and each fix verified on the new one, in the running TUI under tmux against a throwaway vault and config.

To try it:

T=$(mktemp -d); mkdir -p "$T/vault/inbox/Daily" "$T/config"
printf '# Keep me\n\nPrecious content line.\n' > "$T/vault/inbox/Keep.md"
printf '# Index\n\n[[2020-03-31](./Daily/2020-03-31)]\n' > "$T/vault/inbox/Index.md"
printf '# March 31\n' > "$T/vault/inbox/Daily/2020-03-31.md"
ZENNOTES_CONFIG_DIR="$T/config" go run ./cmd/zn tui --vault "$T/vault"
  • Open Keep and press u: Already at oldest change, and the file is intact.
  • Open Index, press gg, jj, gd: the March 31 note opens.
  • Add [terminal] and autosave = false to $T/config/config.toml, relaunch and edit a note: the text is not on disk until :w, and :q refuses.

Not in this PR

  • The README still says the desktop app drops [terminal], but desktop v2.81.0 and later keep it. On older desktops, autosave = false is lost when the app rewrites config.toml.
  • Undoing a reload from disk is still possible, and autosave can then write the older text over the outside edit. The new guard only stops this when the result is blank.
  • Other gd gaps with the desktop ([a](<./My Note>), offering to create a dead link's note, jumping to #heading) are being handled separately.

…nks without .md

Undo: a note opened by a key press starts as an empty editor, and its text
arrived as an undoable change. `u` went back to empty and autosave wrote that
over the file. The first successful read now replaces the placeholder outside
the history (Editor.LoadText), so undo stops at the note as opened. A reload
from disk stays undoable.

A note that started empty can still undo to empty. If undo or redo leaves a
buffer blank while its file has text, autosave, closing a tab and quitting no
longer write it. `:w`, `Ctrl+S` and `:wq` still can, and deleting the text by
hand is an edit that saves as ever.

Autosave: `[terminal] autosave = false` is new, also through `zn config set`
and `:settings`. With it off a note is written only when saved by name. `:q`,
`:qa`, `Ctrl+C`, closing the last tab showing a note and switching vault refuse
over unsaved edits, `:q!` and `:qa!` discard them, and any other exit leaves a
recovery copy. Commands that act on the file itself still save first.

gd: a Markdown link without `.md` was refused as "Not a note". The new
vault.ResolveNoteHref ports the desktop's resolveInternalNoteHref: relative to
the current note, tolerant of a missing extension and percent-encoding, then a
wikilink lookup. A relative path now beats the same path from the vault root,
which matches the desktop and differs from the old order.

Tests: each behavior above, checked to fail with its fix reverted.
Markdown links with spaces in the destination are recognized, with or
without angle brackets, and titles are dropped from the target.

A dead link offers to create the note where it points, so the link
resolves once the note exists. Hrefs that name a file or leave the vault
still report "Not a note".

A #heading or ^block anchor now lands on its target, on Markdown links
and wikilinks alike, in the editor and in reading mode. Same-note anchors
jump instead of offering a note with an empty name.

Bare domains such as google.com open in the browser.
Fix(tui): gd follows links the way the desktop does
The README still warned that the desktop app drops [terminal] when it saves
config.toml. Desktop 2.81.0 stopped doing that, and autosave = false, new in this
release, is one of the settings people would lose by believing otherwise.
@adibhanna adibhanna changed the title Fix(tui): undo cannot wipe a note, autosave can be off, gd follows links without .md zn v0.15.0: undo cannot wipe a note, autosave can be off, gd follows links like the desktop Nov 3, 2026
@adibhanna
adibhanna merged commit 06b79bd into main Nov 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant