Skip to content

Fix(tui): renaming a file updates bare embeds and counts them as uses - #36

Merged
adibhanna merged 2 commits into
mainfrom
claude/nervous-jang-4bf557
Nov 4, 2026
Merged

adibhanna merged 2 commits into
mainfrom
claude/nervous-jang-4bf557

Conversation

@adibhanna

@adibhanna adibhanna commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Uses the resolver added in #35.

Problem

The Files view rewrote links with RewriteAssetLinks, which only knew root-relative and note-relative targets. The desktop and server also resolve a bare file name by unique basename, so on a local vault ![[pic.png]] for assets/pic.png stayed unchanged after a rename and the embed broke. A note whose only link was a bare embed also did not count as a use.

Change

  • Rename takes the asset listing first, then rewrites through the resolver, still through open buffers with a.mutateNote.
  • The use count reads links the same way through a new vault.AssetsReferencedBy.
  • RewriteAssetLinks had no callers left, so it is removed. Its cases that still apply moved to asset_link_rename_test.go.
  • A wikilink that resolves to a note is skipped by the rewrite and the use count, so [[TODO]] stays put when a file called TODO is renamed. This also applies to MCP rename_asset on a local vault.
  • Rename skips trashed notes, like the desktop and server. The use count still includes them.
  • On a server, zn leaves notes to the server, which rewrites them itself, and reloads open buffers.
  • A Markdown link to a name holding an escape, like 50%20off.pdf, now escapes the percent sign so it reads back as that file.
  • wikiCodeMask now uses the desktop's fence closing rules and pairs inline backtick runs of equal length. Note renames share it.

Behaviour change

[other](./assets/report.pdf) in notes/n.md now follows a rename, because the resolver falls back to the vault root like the desktop. It used to stay unchanged.

For Adib to decide

The desktop and server still have the code-example gaps: their rewrites edit double-tick spans and nested fences, and the percent-escape case also differs. This PR only changes zn, so the three copies now differ here.

Testing

  • go test ./... and go vet ./... pass.
  • New tests in workflow_parity_test.go and asset_link_rename_test.go cover a closed note, an open buffer with unsaved text, a note of the same name, trashed notes, a server-style backend, each code form and percent names.
  • Drove the real zn tui in tmux on throwaway vaults:
    • Local: renaming assets/pic.png to my pic.png rewrote ![[pic.png]], ![[assets/pic.png|300]] and [rel](../assets/pic.png), left code alone, and updated the open tab on screen and on disk. Renaming inbox/TODO left [[TODO]] alone.
    • Real znserver (f4a3d0f) with scratch paths: a case-only rename to Pic.png kept every path, refreshed the open tab and left the trash alone.
  • The use count went from 2 on the pre-fix build to 3 on a vault with a note whose only link is a bare embed.

Known limits

  • A raw link renamed to a spaced name on a server stays unbracketed until the server's own resolver is fixed.
  • A trashed note keeps the old file name, so restoring it brings back a dead link.
  • If a server version does not rewrite links itself, zn no longer does it for it. Only the current znserver was tested.

The Files view rewrote links with RewriteAssetLinks, which only knew
root-relative and note-relative targets. On a local vault ![[pic.png]] for
assets/pic.png stayed unchanged after a rename and the embed broke, and a note
whose only link was a bare embed did not count as a use.

Rename now goes through the desktop and server's resolver, still through open
buffers, and the use count reads links the same way through a new
AssetsReferencedBy. RewriteAssetLinks had no callers left, so it is gone.
@adibhanna
adibhanna changed the base branch from claude/mcp-asset-tools-34-d9c88e to main November 4, 2026 17:13
…es alone

Review of the rename found four ways it edited what it should not:

- A wikilink to a note followed a file of the same name, so [[TODO]] became
  [[TODO.old]] when inbox/TODO was renamed. A note now wins, as in the desktop's
  follow-link, in the rewrite and in the use count.
- Code examples were rewritten, because wikiCodeMask paired single ticks and let
  any fence line close a fence. It now uses the desktop's closing rules and pairs
  inline runs of equal length. Note renames share the mask and get this too.
- On a server, a second pass over notes the server had already rewritten read
  the new name against the old listing, so a case-only rename flattened paths.
  zn now leaves notes to the server and reloads open buffers.
- Trashed notes were edited. They are skipped now, like the desktop and server.

A Markdown link to a name holding an escape, like 50%20off.pdf, now escapes the
percent sign, so it reads back as that file.
@adibhanna
adibhanna merged commit f349aba into main Nov 4, 2026
5 checks passed
@adibhanna adibhanna mentioned this pull request Nov 4, 2026
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