CodeEdit icon indicating copy to clipboard operation
CodeEdit copied to clipboard

🐞 ? Changes to File not persisted

Open schmidan opened this issue 2 years ago • 12 comments

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 nor cmd - 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.

schmidan avatar Oct 17 '22 08:10 schmidan

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.

austincondiff avatar Oct 17 '22 16:10 austincondiff

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 avatar Oct 17 '22 20:10 schmidan

@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 avatar Oct 17 '22 21:10 austincondiff

@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?

schmidan avatar Oct 18 '22 07:10 schmidan

I am not entirely sure to be honest. @lukepistrol or @thecoolwinter may be better to answer this one.

austincondiff avatar Oct 18 '22 19:10 austincondiff

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)")
        }
    }

0xWDG avatar Oct 31 '22 15:10 0xWDG

Thanks for the heads up @0xWDG!

austincondiff avatar Oct 31 '22 17:10 austincondiff

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

pabloscloud avatar Nov 02 '22 19:11 pabloscloud

This might be related https://github.com/CodeEditApp/CodeEditTextView/pull/102

lukepistrol avatar Jan 04 '23 16:01 lukepistrol

+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?

PaRkThEcAr avatar Jan 04 '23 17:01 PaRkThEcAr

This might be related CodeEditApp/CodeEditTextView#102

I've checked it and the issue seems to be fixed now.

Wouter01 avatar Jan 04 '23 17:01 Wouter01

I'll create a new release on CodeEditTextView later this day and update the main repo.

lukepistrol avatar Jan 04 '23 20:01 lukepistrol

Fixed in #889

lukepistrol avatar Jan 10 '23 03:01 lukepistrol