Saving rendering - #168
Conversation
dayeggpi
commented
Jun 2, 2026
- 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)
Merging from official
Merge from official
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>
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>
|
@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. 2. No way to see the rendered view until the file is saved. Three other things fell out of that read, which is worth recording since you were the one who noticed the coupling:
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. Closing this as addressed. If any of the three still misbehaves on a build from |