Skip to content

Reduce file revert due to external edits - #1870

Merged
cyanzhong merged 1 commit into
mainfrom
develop
Nov 11, 2026
Merged

cyanzhong merged 1 commit into
mainfrom
develop

Conversation

@cyanzhong

Copy link
Copy Markdown
Contributor

Skip unnecessary reverts when file-change notifications report content identical to the current document.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A race with pending file reads can install stale content after acknowledging disk changes, while skipped raw-data cache refreshes can make Reopen with Encoding restore older text.

2 open issues
What changed in this PR

This PR avoids unnecessary editor reloads when external file-change notifications report bytes identical to the current document, while preserving reloads for changed content and text bundles.

Changes:

  • Add coordinated content comparison and modification-date tracking to the shared document helper.
  • Run external-change handling on the main queue.
  • Add tests for matching content, subsequent saves, changed bytes, unsynchronized text, and text bundles.
File Description
MarkEditMac/​Tests/​EditorDocumentTests.swift Verify external text-bundle edits still reload and preserve assets.
MarkEditMac/​Tests/​EditorDocumentSaveTests.swift Cover skipped reverts, save behavior, and required reloads.
MarkEditMac/​Sources/​Editor/​Models/​EditorDocument.swift Delegate external-change handling to the helper on the main queue.
MarkEditMac/​Modules/​Sources/​AppKitExtensions/​Foundation/​NSDocument+Extension.swift Add coordinated timestamp and content checks before reverting.

Review effort: Balanced

@cyanzhong cyanzhong changed the title Improve file revert due to external edits Reduce file revert due to external edits Nov 11, 2026
@cyanzhong
cyanzhong requested a balanced review from Copilot November 11, 2026 08:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Synchronous file coordination on the main queue can deadlock with a writer waiting for autosave, so the disk read must move off-main with state revalidation before applying the result.

1 open issue
2 resolved since last review

Review effort: Balanced

@cyanzhong
cyanzhong force-pushed the develop branch 2 times, most recently from 742b815 to 84348e7 Compare November 11, 2026 08:55
@cyanzhong
cyanzhong requested a balanced review from Copilot November 11, 2026 08:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An external write matching unsaved edits leaves the editor’s saved undo checkpoint stale, so undoing can incorrectly mark the document clean and allow changes to be discarded on close without prompting.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Regression tests are missing for the new skip-revert path and pending-read retry, leaving identical-content handling, changed-content reloads, and pending-decode behavior unprotected.

1 open issue
1 resolved since last review

Review effort: Balanced

@cyanzhong
cyanzhong merged commit 22eb9db into main Nov 11, 2026
2 checks passed
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