Problem Description
There is an issue with the Cmd+Z (Undo) behavior in the editor.
After further investigation, the issue appears to affect unsaved documents / newly created documents that have not been saved yet.
Current behavior:
Cmd+Z works correctly for files that have already been saved.
- For an unsaved document, pressing
Cmd+Z does not restore the previous editing state.
- Instead, the editor content may be cleared completely.
This suggests that the issue is likely related to the initialization or state management of the Undo history for unsaved documents, rather than a general problem with the editor's Undo functionality.
Steps to Reproduce
- Open the editor.
- Create a new document that has not been saved yet.
- Enter some Markdown content.
- Make additional edits, such as adding, deleting, or modifying text.
- Press
Cmd+Z.
- Observe the editor content.
Current Behavior
For an unsaved document:
Cmd+Z does not correctly undo the most recent edit.
- The editor content may be cleared completely.
- Undo behavior differs from that of an already-saved file.
For already-saved files, Cmd+Z currently works as expected.
Expected Behavior
Cmd+Z should work consistently regardless of whether the document has been saved.
For example:
- Create a new unsaved document.
- Type
ABC.
- Type
DEF.
- Press
Cmd+Z → DEF should be undone.
- Press
Cmd+Z again → the previous edit should be undone.
- The editor should never clear the entire document simply because the document has not been saved yet.
Areas to Investigate
Because Undo works correctly for saved files but fails for unsaved documents, please focus on the following areas:
1. Initial State of Unsaved Documents
Check how a newly created document is initialized:
- How is the editor value / document state initialized?
- Are
null, undefined, and empty string handled differently?
- Is the Undo history initialized correctly?
- Does the lack of a file path cause the new document to follow a different code path?
2. Undo History Initialization
Please verify the editor's history behavior when a new document is created:
- Is the Undo stack initialized correctly?
- Is the initial empty state incorrectly recorded as the only history entry?
- Does the first user edit create a valid history entry?
- Does
Cmd+Z fall back to an incorrect reset/initialization state when the history is empty?
In particular, please check for state transitions such as:
undefined/null → ""
or:
currentContent → initialContent
that could cause Undo to resolve to an empty document.
3. Synchronization Between Document State and Editor State
Check whether the unsaved document has additional state synchronization logic, such as:
- editor state → application state;
- application state → editor;
- draft state;
- autosave state;
- current document state.
Please verify whether the editor correctly restores the previous content on Undo, but that content is then immediately overwritten by another state synchronization process.
4. Saved vs. Unsaved Lifecycle
Compare the lifecycle of:
- a newly created unsaved document;
- the same document after it has been saved.
Identify the differences in initialization, state management, editor lifecycle, and history management that could explain why Undo works after saving but not before saving.
5. Editor Reinitialization
Check whether creating, switching, or saving a document causes the editor instance or its content to be reinitialized.
Please verify that these operations do not unexpectedly:
- recreate the editor instance;
- reset the editor content;
- clear the Undo history;
- initialize the editor with an empty value.
Verification Requirements
After the fix, please verify at least the following:
Cmd+Z works correctly in a newly created unsaved document.
- Multiple edits can be undone step by step.
Cmd+Z never clears the entire unsaved document unexpectedly.
- Deleting a large amount of content can be correctly undone.
- The flow
Create → Edit → Undo → Save works correctly.
- Undo continues to work correctly for already-saved files.
- Switching between documents does not corrupt the Undo history.
- If Redo is supported,
Cmd+Shift+Z continues to work correctly.
- Add or improve regression tests covering Undo behavior for unsaved documents.
Acceptance Criteria
Problem Description
There is an issue with the
Cmd+Z(Undo) behavior in the editor.After further investigation, the issue appears to affect unsaved documents / newly created documents that have not been saved yet.
Current behavior:
Cmd+Zworks correctly for files that have already been saved.Cmd+Zdoes not restore the previous editing state.This suggests that the issue is likely related to the initialization or state management of the Undo history for unsaved documents, rather than a general problem with the editor's Undo functionality.
Steps to Reproduce
Cmd+Z.Current Behavior
For an unsaved document:
Cmd+Zdoes not correctly undo the most recent edit.For already-saved files,
Cmd+Zcurrently works as expected.Expected Behavior
Cmd+Zshould work consistently regardless of whether the document has been saved.For example:
ABC.DEF.Cmd+Z→DEFshould be undone.Cmd+Zagain → the previous edit should be undone.Areas to Investigate
Because Undo works correctly for saved files but fails for unsaved documents, please focus on the following areas:
1. Initial State of Unsaved Documents
Check how a newly created document is initialized:
null,undefined, and empty string handled differently?2. Undo History Initialization
Please verify the editor's history behavior when a new document is created:
Cmd+Zfall back to an incorrect reset/initialization state when the history is empty?In particular, please check for state transitions such as:
undefined/null → ""or:
currentContent → initialContentthat could cause Undo to resolve to an empty document.
3. Synchronization Between Document State and Editor State
Check whether the unsaved document has additional state synchronization logic, such as:
Please verify whether the editor correctly restores the previous content on Undo, but that content is then immediately overwritten by another state synchronization process.
4. Saved vs. Unsaved Lifecycle
Compare the lifecycle of:
Identify the differences in initialization, state management, editor lifecycle, and history management that could explain why Undo works after saving but not before saving.
5. Editor Reinitialization
Check whether creating, switching, or saving a document causes the editor instance or its content to be reinitialized.
Please verify that these operations do not unexpectedly:
Verification Requirements
After the fix, please verify at least the following:
Cmd+Zworks correctly in a newly created unsaved document.Cmd+Znever clears the entire unsaved document unexpectedly.Create → Edit → Undo → Saveworks correctly.Cmd+Shift+Zcontinues to work correctly.Acceptance Criteria
Cmd+Zclearing content in unsaved documents.Cmd+Zcorrectly restores the previous editing state.