Fix false "unsaved changes" prompt when a document is reverted to its original state - #9
Fix false "unsaved changes" prompt when a document is reverted to its original state#9beefllama wants to merge 4 commits into
Conversation
The revert check treated m_lastKnownFileText as authoritative even where the file behind it had gone or had been changed by someone else, so two paths reported a document with unsaved work as clean, and Main.qml's onClosing gates purely on backend.modified. Deleting the file externally left the old baseline in place, because the watcher skipped the clear for deletions. Editing and undoing back to the deleted file's text then read as unmodified, set the status to "Saved <name>", and dropped the recovery snapshot for a file that no longer existed; closing the window discarded the only remaining copy without a prompt. The other path is dismissal. ExternalChangeDialog closes on Escape without reaching keepExternalVersion() or reloadFromDisk(), and keepExternalVersion() also lands on an unknown baseline when the disk read fails, so the empty string stood in for "we do not know". Emptying the editor then matched it and cleared the modified flag. The watcher now goes through setKnownFileContents() like every other writer, deletions included, and the comparison only trusts an empty baseline for a document with no file behind it -- which is the untitled case issue omacom-io#4 is about, and it still passes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
The baseline approach is right. Two paths let it call a document clean when we did not actually know what was on disk, so I pushed one fix to Pushed e08b2ff.
The fix routes the watcher through Still open, not pushed:
Worth knowing about #13: it inserts an early return into Separately and not yours: |
Summary
Fix the false "unsaved changes" prompt when a document is reverted to its original state.
Details
Backend::editorTextChanged() set the modified flag whenever the editor text differed from the last known text, but never cleared it when the text returned to its baseline. Typing text and then deleting it back to the original content left modified = true, so closing the window prompted to save changes that didn't exist.
Fix
editorTextChanged() now compares the current text against a baseline (the on-disk contents, or an empty string for a new file) and clears the modified flag when they match.