-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Reflect External File Changes #2075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thecoolwinter
wants to merge
16
commits into
CodeEditApp:main
Choose a base branch
from
thecoolwinter:feat/reflect-external-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Reflect External File Changes #2075
thecoolwinter
wants to merge
16
commits into
CodeEditApp:main
from
thecoolwinter:feat/reflect-external-changes
Conversation
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
thecoolwinter
added a commit
that referenced
this pull request
Jul 10, 2025
### Description Implements editor restoration, helping ease the user experience for longer editing tasks spanning multiple files. Users expect opened tabs to retain the scroll position, cursors, and undo stack. To facilitate this, we receive a stream of state updates from the editor and save them to a SQLite DB. When a file is opened again, the state is restored from that DB. Ideally this is transparent to the user. However, there is one very slight UX flaw that this doesn't address: highlighting. When a user restores an editor there can be a flash as the highlighter works to do syntax highlighting on the newly opened editor. Some potential future directions: - The text storage object that outlives editors does retain color information, if we could avoid wiping that color information when an editor is loaded we could avoid that slight delay. - To do that, we need to store that state with the storage object somehow. Either through a custom text attribute (could be finicky) or maybe by subclassing NSTextStorage and adding a flag. > [!NOTE] > This includes a mechanism for sharing undo stacks for editors during a workspace's lifetime. As @austincondiff mentioned on discord, it should add a undo frame when a file is updated externally. This PR notably does not include that change. I'll be adding it in #2075 ### Related Issues * closes #2057 ### Checklist - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots https://github.com/user-attachments/assets/6a9ff5ea-743e-4183-83c9-b774915b0c35
austincondiff
approved these changes
Jul 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this all looks really good. Nice work!
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.
Description
Implements reflecting external changes in open files. If a file has no unsaved changes, and is notified that the contents changed, it reloads the contents.
NSDocument
already handles asking the user if they want to overwrite the contents of the file or use the disk version if the user attempts to save to a file that has been updated since they edited the file.When a successful reload happens, the
CodeFileDocument
will also register a new undo frame with the new contents. This allows the user to undo changes that are reflected in the editor.When a file is updated externally and there are no open editors, the cached undo stack is cleared.
Detailed changes:
CodeFileDocument.presentedItemDidChange
to handle notifications about file changes.isDocumentEdited
is false, we block the calling thread and reload the document.CodeFileDocument.read
, we check to see if the file has already been read into theNSTextStorage
object.CodeFileDocument
s intoCEWorkspaceFile
. Previously it was in a few different places.UndoManagerRestoration
to receive file system events. It uses these to invalidate undo stacks where necessary.CodeFileView
to use the file document's object ID as SwiftUI's identifier. This fixed a bug where a document was sometimes 'cached' by the document controller and meant SwiftUI didn't load up a new view for the new document. This ID is stable while a file is open in an editor.CodeFileDocument
that were causing the file to not reload when it was closed and opened again.EditorLayout+StateRestoration.swift
are all related to this.[weak codeFile]
are similarly related.Related Issues
Checklist
Screenshots
Demo of new behavior. I first undo modifications to the open file, then make some modifications. The changes are added to the current undo stack. I cause a lint again and then undo all the changes and close the file. I then make more external changes (invalidating the undo stack) and open the file, where Command-Z no longer has any effect because of the changes that happened while the file wasn't opened.
CodeEdit.-.Reflect.External.Changes.Demo.Long.mp4