Skip to content

Unsaved text editor changes are lost or corrupted when the open file is renamed to another extension #4299

Closed

Description

@JammingBen

Bug Description

If a file open in the text editor is renamed to a different extension before its first save (e.g. notes.md -> notes.txt), the editor's unsaved changes are lost or corrupted.

The resources store holds the same object as the AppWrapper's resource until the first save. The rename therefore updates resource.extension in place. The text editor's Yjs adapter picks its content type from resource.extension on every call, while the mounted editor keeps the content type it was loaded with.

Reproduction Steps

  1. Open notes.md in the text editor. Don't type and don't save.
  2. Rename it to notes.txt via the sidebar or another tab.
  3. Type something. The console shows [yjs] serialize for content update failed: ... Unknown node type.
  4. Close the editor. There's no unsaved-changes prompt and the edits are gone.

Expected Outcome

The edits stay intact. At worst, saving fails with a conflict, so the user can copy the content or use "Save As".

Actual Outcome

  • md -> txt: serializing the markdown document as plain text throws ("Unknown node type"). The error is swallowed, the editor never becomes dirty, closing doesn't ask, and the edits are lost.
  • txt -> md: the content gets saved with markdown escaping (doubled newlines, \_, \#, 1\.).

After the first save the AppWrapper holds its own copy of the resource and the problem no longer occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions