Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Specify edit origin for color editor widgets in order to batch undos #2790

Merged
merged 2 commits into from
Feb 8, 2013

Conversation

njx
Copy link

@njx njx commented Feb 3, 2013

Fixes #2721. @peterflynn -- could you look at this one?

This takes advantage of the newly-exposed "origin" parameter to replaceRange() in CodeMirror. For each color editor, we create a unique origin string. This makes it so that all consecutive edits from a given color editor are batched into a single undo. This is slightly different from our v2 behavior, where the edits would only be batched if they were close together in time. We could implement that heuristic instead, but batching all edits from a given editor together seems to make sense as well, and is more predictable. (Of course, if there are intervening edits elsewhere in the document, they will interrupt the undo batching, as you would expect.)

Note that the change to Editor._applyChanges() isn't actually necessary for this bug fix and probably won't have any effect in the codebase today, but it seems to make sense semantically (i.e., if undos are batched in the underlying document, they should be batched in the synchronized editor, and vice versa). That issue should go away anyway when we switch to CM's own doc/view separation implementation.

@ghost ghost assigned peterflynn Feb 3, 2013
@peterflynn
Copy link
Member

Reviewing...

* If origin starts with "+", then consecutive edits with the same origin will be batched for undo if
* they are close enough together in time.
* If origin starts with "*", then all consecutive edit with the same origin will be batched for
* undo.
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to state that if you use neither prefix, the edits will never get batched? (Barring a batchOperation() that is).

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@peterflynn
Copy link
Member

@njx: done reviewing. Looks good other than those nits. I did notice a new bug, #2805, that I think is minor enough to defer from this sprint.

@njx
Copy link
Author

njx commented Feb 8, 2013

Ready for re-review. Also added a simple unit test.

@peterflynn
Copy link
Member

Looks good -- merging.

(I noticed one nit, that the type declaration on _origin is wrong, but we can fix that later esp. since it's not public API).

peterflynn added a commit that referenced this pull request Feb 8, 2013
Specify edit origin for color editor widgets in order to batch undos
@peterflynn peterflynn merged commit 4a052a8 into cmv3 Feb 8, 2013
@peterflynn peterflynn deleted the nj/issue-2721 branch February 8, 2013 04:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants