Skip to content

Saving rendering - #168

Closed
dayeggpi wants to merge 11 commits into
sftwrdotdev:masterfrom
dayeggpi:saving-rendering
Closed

Saving rendering#168
dayeggpi wants to merge 11 commits into
sftwrdotdev:masterfrom
dayeggpi:saving-rendering

Conversation

@dayeggpi

@dayeggpi dayeggpi commented Jun 2, 2026

Copy link
Copy Markdown
Contributor
  • Improvement: When in rendered markdown view with file that was never saved/created, control+s doesnt work (nothing happens). also added save/save as in menu.
  • Improvement: allow user to switch to rendered view without saving/creating file : if file was created and user switches to rendered view, it would save file automatically or ask user to save file before (depending on "save automatically" option), no way to see rendered view until file is saved.
  • Bug fix: "autosave ON + confirm before save ON" now triggers prompt to ask user if they want to save (every 1.5seconds)

PathGao added a commit that referenced this pull request Aug 2, 2026
With a document that was never saved, Ctrl+S in reading mode did nothing at
all. `toggleEdit` only runs its save-or-confirm flow for tabs that already
have a path, so an untitled buffer switches to reading mode with its content
still unsaved -- and the keydown handler then suppressed the one shortcut
that could rescue it. The only way to keep that text was to switch back to
the editor first, which is not something the shortcut's silence suggests.

Saving is not mode-specific. The guard now asks whether there is anything to
write rather than which pane happens to be visible. A saved, unmodified
document stays a no-op, so the shortcut cannot churn its mtime and wake the
file watcher, and the HOME tab is excluded by the same condition without
being named. `documentSession.saveContent` already opens the Save dialog for
a pathless tab, so reading mode needs no extra plumbing.

`preventDefault` now runs unconditionally, including for the no-op case;
previously reading mode let the shortcut fall through to the webview's own
Save Page dialog.

Reported by @dayeggpi in #168.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
PathGao added a commit that referenced this pull request Aug 3, 2026
Leaving the editor re-read the file from disk, so a dirty tab had to
resolve a save decision - silently write, or answer a modal - before the
rendered view could appear. dayeggpi reported this in #168: "no way to
see rendered view until file is saved."

The prompt was never about losing data. Nothing is lost by switching
view mode; the buffer stays in memory either way. It existed because the
exit path called `loadMarkdown(tab.path)`, and reading the disk on a
dirty tab would show the wrong text. The untitled branch two lines below
already rendered the buffer instead - and #407 extracted
`renderTabPreviewFromRaw` for the print path, which is exactly the same
operation with a real path. Both exits now use it.

That also removes three problems the disk read carried: the exit took
the 50KB preview branch, so leaving the editor on a large file
re-truncated a complete buffer and refused saves until the background
read finished; `loadMarkdown` writes into the *active* tab, so
`toggleSplitView(tabId)` on a background tab would have yanked the
active one; and `if (!success) return` kept the tab in edit mode when
the write failed - which for a read-only file or a lossily decoded
buffer meant reading mode was permanently unreachable.

One segment of that block is kept, narrowed to `autoSave &&
!confirmBeforeSave`: the auto-save effect treats a tab as writable only
while `isEditing || isSplit`, and clears its pending timer otherwise, so
leaving edit mode drops the scheduled write. That flush is the last
chance before the window closes, not a condition of the switch.

Closing a tab and closing a window still ask. Those buffers are about to
cease to exist; this one is not. VS Code, Obsidian and Typora all render
the buffer, and none of them asks.

Co-authored-by: PathGao <gaoyanbo@gaoyanbodeMacBook-Air.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
@PathGao

PathGao commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

@dayeggpi — all three of these have landed, though not from this branch. Thank you for the report; the third one in particular took some tracing to find the cause of.

1. Ctrl+S does nothing in rendered view on a never-saved file, and there is no Save / Save As in the menu.
Fixed in #365. Saving works from reading mode, the menu carries both entries, and the untitled case (path === '') is included rather than falling through.

2. No way to see the rendered view until the file is saved.
Fixed in #421. The cause turned out not to be a save policy at all: leaving the editor called loadMarkdown(tab.path), which re-reads the file from disk, so a dirty tab had to resolve a save decision first or the preview would show the wrong text. It now renders the buffer — which the untitled branch two lines below was already doing. The modal is gone entirely.

Three other things fell out of that read, which is worth recording since you were the one who noticed the coupling:

  • leaving the editor on a large file took the 50 KB preview branch, re-truncating a complete buffer and refusing saves until a background read finished;
  • if (!success) return kept the tab in edit mode when the write failed — and saveContent returns false permanently for a read-only file, so reading mode was unreachable for that tab, forever;
  • loadMarkdown writes into the active tab, so toggling split view on a background tab would have pulled the active tab's content over.

Closing a tab and closing a window still ask. Those buffers are about to cease to exist; a view toggle's does not.

3. autosave ON + confirm-before-save ON prompts every 1.5 seconds.
Fixed by 49cb75b, before this round. With confirmBeforeSave on, background auto-save is disabled outright rather than firing and then asking — the Settings label promises confirmation before each save, so a silent debounced write contradicts it either way.

Closing this as addressed. If any of the three still misbehaves on a build from master, please reopen — the second one in particular changed behaviour rather than just fixing a failure, and it is worth a second pair of eyes.

@PathGao PathGao closed this Aug 3, 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.

2 participants