CodeEdit
CodeEdit copied to clipboard
🐞 ? Changes to File not persisted
Description
This might be a silly permission or sandbox issue/misconfiguration on my part but i did not find anything about it in the readme/faq.
Changes to files are not written by CodeEditApp.
- It does not matter if it is a file created by CodeEdit or if it is an existing file.
- Neither
File > Save
norcmd - s
works
To Reproduce
- The changes look as if they are saved but closing reopening the file/tab or just navigating to another open file and coming back will reload the file without the edits.
- There are no errors in xcode console nor in console.app.
- I sign CodeEdit with my (Personal Team)
- File permission is read-write for my user (also tried
everyone
) - rebooted
Version information
Git: Branch main - commit 29470d94f5fc3ad15b86e3dc4baca805dcee01ef CodeEdit: [e.g. 1.0] macOS: 12.3 Mac mini (M1, 2020) & 12.5 MacBook Pro (2019) Xcode: 13.3 & 14.0.1
Additional context:
https://user-images.githubusercontent.com/435494/196132257-14661f91-1ce0-4679-bb8c-36fda716265c.mp4
ps. Even changed the implementation to getSelectedCodeFile()?.save(withDelegate: self, didSave: #selector(didSave), contextInfo: nil)
to see if i get any more feedback.
The delegate is called properly with didSave==True
without any additional info.
I wonder if this has something to do with making edits in a temporary tab. When you make any changes, this temporary tab should convert to a normal tab. I notice from the video, the tab label is still in italics after you start typing.
You are right. This notification observer is never firing:
WorkspaceDocument.swift:294
NotificationCenter.default.addObserver(
self,
selector: #selector(convertTemporaryTab),
name: NSNotification.Name("CodeEditor.didBeginEditing"),
object: nil)
This also seems to be the only occurrence of that name in the code base. Has the name changed and was forgotten to be updated somewhere?
I tried STTextView.willChangeNotification
but then it transitions to a normal tab immediately
@schmidan It is possible. We may need to build that in if it doesn't yet exist. It should be converted to a standard tab once didBeginEditing is fired.
@austincondiff would that have to be in STTextView
?
That module currently fires STTextView.didChangeNotification
but it does so also on opening an existing document.
There is no didBeginEditing
Anyhow, using the didChangeNotification
does not solve the underlying issue: changes are not persisted.
Does the NSDocument somehow not receive the changes from the editor?
I am not entirely sure to be honest. @lukepistrol or @thecoolwinter may be better to answer this one.
CodeEditor.didBeginEditing
is used to determine that the document is/was changed (for keeping the tab open).
If there are no changes, the tab will be switched to the newly opened file.
The biggest problem is that NSDocument.save()
seems to be unrelaiable.
in another project i've used the following code what does work for us (in all cases).
/// Save document. (custom function)
public func saveFileDocument() {
guard let url = self.fileURL,
let contents = content.data(using: .utf8) else {
fatalError("\(#function): Failed to get URL and file type.")
}
do {
try contents.write(to: url, options: .atomic)
} catch {
fatalError("\(#function): Failed to save, \(error.localizedDescription)")
}
}
Thanks for the heads up @0xWDG!
https://user-images.githubusercontent.com/93644977/199585248-6693e2dc-f00e-4892-b85e-0523363ba921.mov
I can confirm this isn't an issue on their part only
This might be related https://github.com/CodeEditApp/CodeEditTextView/pull/102
+1 on this issue as well. latest build as of 1-4-2023 seems to have the same issue (not that a fix has been pushed yet).
would it be helpful if i gather any console logs?
This might be related CodeEditApp/CodeEditTextView#102
I've checked it and the issue seems to be fixed now.
I'll create a new release on CodeEditTextView later this day and update the main repo.
Fixed in #889