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

Operation.toJSON does not save selection's value - Saving history #2672

Closed
callingmybluff opened this issue Mar 28, 2019 · 4 comments
Closed

Comments

@callingmybluff
Copy link

Do you want to request a feature or report a bug?

A bug

What's the current behavior?

https://jsfiddle.net/Ismaeel/xvgoqLn2/

  1. Place the cursor anywhere inside the text
  2. Click on Click To Do Nothing (it will reset the history by using the history itself, but each operations is re sat to its value after to/from JSON: op = Operation.fromJSON(op.toJSON())
  3. Click on the redo button, which calls the native this.editor.undo.
  4. An error appears in the console: Uncaught TypeError: Cannot read property 'merge' of undefined

Slate 0.44.12, Chrome latest (73.0.3683.86 64bit), and Windows7

What's the expected behavior?

I would like to save the history in a JSON and load from a JSON too (replay what the user did step per step). I can use something like deep-diff, but using them would be much faster (although maybe not memory-friendly).

If you think this is a valid bug and you would accept a pull request for it, I will happily do that. Please let me know if you want me to create an example for it, too (or extend the versioning example as it only saves in memory for now).

@isubasti
Copy link
Contributor

@callingmybluff there's an option to preserveSelectionon toJSON

@callingmybluff
Copy link
Author

@callingmybluff there's an option to preserveSelectionon toJSON

Did you try the example? It does nothing, or I am using it wrong? According to the documentation, it reserves JSON for the data as a whole, not to Operation.

https://jsfiddle.net/Ismaeel/xvgoqLn2/35/

@callingmybluff
Copy link
Author

Possible solution would probably be by adding (as in: https://jsfiddle.net/Ismaeel/xvgoqLn2/40/) :

if (options.preseveSelection && op.selection)
    json.selection = op.selection.toJSON();

I will create a pull request for it

@ianstormtaylor
Copy link
Owner

As of #3093 (which was just merged), I believe this issue is no longer applicable, because a lot has changed. I'm going through and closing out any potential issues that are not out of date with the overhaul. Thanks for understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants