Repository navigation
fix(desktop): prevent data loss when closing after Source Code mode edits - #4627
Merged
Merged
Conversation
…a loss (#4455) Editing a file in Source Code mode and then closing the window without first switching back to WYSIWYG silently skipped the unsaved-changes prompt, losing the edits. Source-mode commits reach LISTEN_FOR_CONTENT_CHANGE without an editor `history`, and the dirty check is entirely history-based: a missing history left `isSaved` untouched and actually fell into the restore branch that resets it to `true`, so the close path saw nothing unsaved. Decide dirty state from a content comparison when the change carries no history (the Source Code path), and only let the history branch restore `isSaved = true` when a history is present, so a source-mode caret move can no longer clear a pending dirty flag. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Source Code mode edits now mark the tab dirty, so closing the window after editing in Source Code mode shows the unsaved-changes prompt instead of silently discarding the edits.
Why (data loss)
LISTEN_FOR_CONTENT_CHANGEdecidesisSavedentirely from the editorhistory(lastEditIndex/editEntry.idvslastSavedHistoryId). Source Code mode (sourceCode.vue) commits content without ahistoryfield, so:isSavedtofalse, andelse ifrestore branch and resetsisSavedtotrue.The close path (
LISTEN_FOR_CLOSE) collectstabs.filter(t => !t.isSaved); withisSavedstilltrue, it finds nothing unsaved and closes the window with no save dialog. Editing in Source Code mode and closing without switching back to WYSIWYG therefore loses the edits. (A source-mode caret move could even clear a dirty flag set earlier in WYSIWYG, via the same restore branch.)Fix
When the content-change carries no
history(the Source Code path), decide dirty state from a content comparison (markdown !== oldMarkdown). The history-based branch is unchanged for WYSIWYG, and the "restoreisSaved = true" branch now only runs when a history is present, so a source-mode caret move can no longer clear a pending dirty flag.Tests
New
test/unit/specs/source-mode-dirty.spec.ts(RED→GREEN): source-mode edit → dirty; source-mode caret move (unchanged content) → stays saved; WYSIWYG history path → unchanged. Full desktop unit suite (28 files / 653 tests), lint, andvue-tsctypecheck pass.Fixes #4455
🤖 Generated with Claude Code