Skip to content

Ink written before a save survives the file changing on disk (#273) - #279

Merged
Joost-8 merged 2 commits into
mainfrom
issue-273-lost-ink
Nov 21, 2026
Merged

Joost-8 merged 2 commits into
mainfrom
issue-273-lost-ink

Conversation

@OskarRabenda

Copy link
Copy Markdown
Collaborator

Closes #273.

Cause (proven in the real-Obsidian rig with Obsidian 1.15.1; not yet seen on an iPad)

2.10.0's #246 fix set isPlaintext = false on the notebook view. Obsidian 1.15.1's TextFileView.loadFileInternal (read from obsidian-1.15.1.asar) runs on every modify of the open file:

r = await vault.read(file); n = this.lastSavedData; this.lastSavedData = r;
if (!clear && n) { if (n === r) return;
  if (this.dirty) { a = this.getViewData(); if (a === r) return;
    if (a !== n && this.isPlaintext) r = merge(n, a, r) } }
this.setData(r)   // -> setViewData(r, false)

Before, the text was merged and then held. Now it is a plain replace. FineNotes keeps the view dirty for a long time: the write-hold puts saves off while the pen writes, then the background encode runs. Any modify in that window swaps the notebook for the file, which drops the newest strokes. InkSurface.setDocument clears the history, so undo cannot bring them back. That matches the report.

What fires the modify on the reporter's iPad is unproven. It can be:

  • a sync landing (iCloud or Obsidian Sync);
  • another app or plugin writing the file;
  • Obsidian's own race: lastSavedData is read after the awaited read, and the mobile adapter queues reads and writes, so a save that starts during the read makes the view's own previous save look like an outside change.

Repro in the rig, build without the fix: stroke A, wait for the save, stroke B, then append a line to the file from outside → the notebook holds only A, and undo is empty. With the fix: every stroke is kept, the appended text is kept, diskReloads.merged = 1, and the file equals the view after the next save.

Fix

  • src/model/reload-merge.ts (pure):
    • OwnTexts remembers the last three texts this view loaded or wrote.
    • mergeReload(base, local, remote) is a three-way merge by id on the stored form.
    • Pages and elements added on either side are kept. One removed on one side goes, unless the other side changed it. A conflict keeps this device's version.
  • InkView.loadViewData, on a reread of the same file:
    • Own text: a reread of a text this view already had is skipped. The notebook and its undo history stay, and a save is asked for.
    • Unsaved changes here: the file's version is merged with them, and the result is saved.
    • Nothing unsaved: the file is loaded as before.
  • Diagnostics (per the ledger's "ship diagnostics with the first fix"):
    • The diagnostics export gets diskReloads: {own, merged, carried, replaced}.
    • The input debug overlay gets disk=own…/merged…+…/replaced….

Ruled out from the code: pen rejoin's History.withdraw, Scribble to erase and joined-page mirrors. None of them changed since 2.8.x.

Tested

  • tests/model/reload-merge.test.ts (13 cases) and 4 new view cases in tests/view/ink-view-file.test.ts. The first view case fails on the old code.
  • All CI gates pass locally: typecheck, lint, lint:review, format:check, test (9724 passed, 7 skipped), build.
  • Real-Obsidian rig (desktop, 1.15.1), before and after, as above.
  • Not tested on an iPad, or with a real iCloud or Obsidian Sync change.

Nothing visible changed, so there is no review page.

🤖 Generated with Claude Code

OskarRabenda and others added 2 commits November 20, 2026 14:42
Since 2.10.0 the notebook view is not plain text to Obsidian (#246), so a
modify event while the view had unsaved ink replaced the notebook with the
file: the newest strokes vanished and, with the history cleared, undo could
not bring them back. Obsidian's loadFileInternal also reads lastSavedData
only after its awaited read, so a save starting meanwhile made the view's
own previous save look like a change from elsewhere.

A reread of a text this view loaded or wrote is now skipped (history kept),
and a real change from elsewhere is merged three ways, by id, with the
unsaved ink (src/model/reload-merge.ts). The diagnostics export and the
debug HUD count what happened (diskReloads).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A copy of the notebook arriving late from another device made ink this
device had already saved look erased over there, and the merge dropped
it. It also did so with nothing unsaved here, and for a page with no
unsaved changes, which was taken whole from the file.

- Anything this device has that the file lacks is kept, saved or not, and
  saved back. Price: an erase made on another device while this one holds
  the notebook open comes back.
- Pages are looked inside even when unchanged here, and a list the file
  stores as absent (no pictures) counts as empty, not as removed.
- Two devices that counted on from the same highest id gave different new
  strokes one id; the merge kept only this device's. Both are kept now, the
  other renumbered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Joost-8

Joost-8 commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks Oskar, this landed in #286 as a merge, so your commit is in main as it was. On top of it:

  • the merge keeps anything this device has that the incoming file lacks, so an older copy from another device no longer drops saved ink (an erase made elsewhere while the notebook is open can come back);
  • two devices that gave new strokes the same id keep both;
  • an empty read while the file is being written no longer blanks the notebook. The rig caught that one when an older copy was copied over the file.
    Tested together in the real-Obsidian rig.

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.

Loosing handwriting while writing

2 participants