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

Implement #1452 #5236

Merged
merged 6 commits into from Oct 11, 2023
Merged

Implement #1452 #5236

merged 6 commits into from Oct 11, 2023

Conversation

NotLazy
Copy link
Contributor

@NotLazy NotLazy commented Jul 4, 2023

Issue #, if available: #1452

Description of changes: Implements the toJSON and fromJSON methods to allow saving and restoring undoManager's state.

// Example
var undoManager = editor.session.getUndoManager();
var state = undoManager.toJSON();
// ... then later ...
undoManager.fromJSON(state);

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@NotLazy
Copy link
Contributor Author

NotLazy commented Jul 4, 2023

Honestly I'm disappointed this hasn't been done sooner, and that the undoManager has had empty toJSON and fromJSON methods for this long.

@NotLazy NotLazy mentioned this pull request Jul 5, 2023
@codecov
Copy link

codecov bot commented Jul 10, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (7a6b83e) 87.41% compared to head (73b7c02) 87.43%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5236      +/-   ##
==========================================
+ Coverage   87.41%   87.43%   +0.01%     
==========================================
  Files         574      574              
  Lines       45613    45652      +39     
  Branches     6935     6935              
==========================================
+ Hits        39873    39914      +41     
+ Misses       5740     5738       -2     
Flag Coverage Δ
unittests 87.43% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/undomanager.js 78.39% <100.00%> (+0.89%) ⬆️
src/undomanager_test.js 99.71% <100.00%> (+0.03%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@andredcoliveira andredcoliveira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Thank you for the contribution! Empty toJSON and fromJSON methods are definitely not useful.

The changes look good to me; could you add some basic tests that ensure the output is as expected?

Comment on lines 239 to 250
toJSON() {

return {
$redoStack: this.$redoStack,
$undoStack: this.$undoStack
};
}

fromJSON() {

fromJSON(json) {
this.reset();
this.$undoStack = json.$undoStack;
this.$redoStack = json.$redoStack;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you introduce testing for the two methods?

@phiden1
Copy link

phiden1 commented Sep 30, 2023

Close

@NotLazy
Copy link
Contributor Author

NotLazy commented Sep 30, 2023

Close

This affects undomanager not edit session. Don't close.

@NotLazy
Copy link
Contributor Author

NotLazy commented Sep 30, 2023

Hey! Thank you for the contribution! Empty toJSON and fromJSON methods are definitely not useful.

The changes look good to me; could you add some basic tests that ensure the output is as expected?

I'll add tests as soon as I have a chance.

@NotLazy
Copy link
Contributor Author

NotLazy commented Oct 8, 2023

Small little update about the usage of these changes, if you want to save state to localStorage or upload to remote server.

// Example
var undoManager = editor.session.getUndoManager();
var state = undoManager.toJSON();
var json = JSON.stringify(state);
// ... then later ...
undoManager.fromJSON(state);

That is to say, the toJSON method actually returns a "safe" instance object, not a string.

Just let me know if you'd prefer a string and I'll happily make the change.

@NotLazy
Copy link
Contributor Author

NotLazy commented Oct 8, 2023

@andredcoliveira This is ready to merge now, unless you'd rather me convert the methods to return/accept a string instead of an object.

@InspiredGuy InspiredGuy merged commit 6a2665d into ajaxorg:master Oct 11, 2023
3 checks passed
@InspiredGuy
Copy link
Contributor

Thank you for the contribution! Returning object is fine, it is consistent with existing toJSON method in Ace codebase.

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

Successfully merging this pull request may close these issues.

None yet

4 participants