Skip to content
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

Undo in editor erases everything after page reload #964

Closed
samdev-7 opened this issue Mar 14, 2023 · 3 comments
Closed

Undo in editor erases everything after page reload #964

samdev-7 opened this issue Mar 14, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@samdev-7
Copy link
Member

samdev-7 commented Mar 14, 2023

Pressing undo (control/command z) after a reload results in a blank file, causing you to lose all your progress.

Expected behavior

To go back to the previous edit and if no previous edit is saved, to do nothing.

How to reproduce

  1. Open the editor.
  2. Type something.
  3. Wait for it to save.
  4. Repeat 2-3 a couple of times.
  5. Press undo, it works.
  6. Reload the page.
  7. Press undo.
  8. Your entire code is erased.

As there is no file history, if you do not have a backup, you risk losing your game forever if you do not redo in time.

@samdev-7 samdev-7 added the bug Something isn't working label Mar 14, 2023
@grymmy
Copy link
Contributor

grymmy commented Mar 14, 2023

This is 100% reproducible on my end. Thank you for the instructions.

@grymmy
Copy link
Contributor

grymmy commented Mar 14, 2023

It appears that when loading up the initial code in the editor using CodeMirror, we dispatch a new (undoable) modification of the text. Thus, when the user hits 'undo', the editor undoes that text addition, which results in all code being removed.

Relevant code:
if (props.initialCode) editor.dispatch({ changes: { from: 0, insert: props.initialCode } })

Looking into prepopulating the editor now without causing a new transaction to be put into the history stack.

@samdev-7
Copy link
Member Author

Seems to be fixed with the recent changes.

@grymmy grymmy closed this as completed Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants