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

Custom undo/redo possible for block? #13892

Closed
amyriounis opened this issue Feb 15, 2019 · 3 comments
Closed

Custom undo/redo possible for block? #13892

amyriounis opened this issue Feb 15, 2019 · 3 comments
Labels
[Feature] History History, undo, redo, revisions, autosave. [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@amyriounis
Copy link

amyriounis commented Feb 15, 2019

Is there any way of opting-out of the default undo/redo behavior and handling block history explicitly in my block?

I've tried my luck with this:

withDispatch( ( dispatch ) => {
		const {
			createUndoLevel,
			redo,
			undo,
		} = dispatch( 'core/editor' );
		return {
			onCreateUndoLevel: createUndoLevel,
			onRedo: redo,
			onUndo: undo,
		};
	} )

but it doesn't seem to have any effect on how undo/redo affects my block. Maybe I'm not using it the right way. Could you please provide an example of how a block can handle it's own history?

Why I need this
My block needs to be aware of it's innerBlocks block types and performs checks on them to assure it. If something is out of place (a block of another type is inside it) it creates a new block of the correct type and moves the stray block* inside it. You can see how a normal undo/redo operation would be problematic in this context, as the past/future result of an undo/redo operation consists of more than one actions.

I think that essentially what I need to do is to define when undo levels are being created for my block. Although, I cannot seem to find a way to prevent automatic in-between undo levels from being created, which would eventually lead to corrupt block state.

*stray block = block of a type that shouldn't be a direct child of the parent block (think of a row - column implementation)

@swissspidy swissspidy added [Type] Help Request Help with setup, implementation, or "How do I?" questions. [Feature] History History, undo, redo, revisions, autosave. labels Feb 15, 2019
@jorgefilipecosta
Copy link
Member

There is some work in progress as part of the phase 2 scope to improve undo behaviors maybe the new solution is useful here. cc: @aduth, @mcsf

@mcsf
Copy link
Contributor

mcsf commented Feb 18, 2019

At the moment, it's looking like the next improvements to Undo/Redo (see long soul-searching in #8119) will preserve the model of tracking the editor's history as a whole, as opposed to a scenario of per-block history management. That said, if we do end up implementing the concept of sagas or history amends to a given block, that could be useful to the present intended use case.

However, your use case is currently not supported, @amyriounis.

@amyriounis
Copy link
Author

@mcsf Thanks for the response, it properly addresses my initial question, and so as far as I am concerned, this issue can be closed. If you think keeping it open might be of use to someone else or serve as a reminder towards another direction regarding editor's history model further implementation, no problem either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] History History, undo, redo, revisions, autosave. [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

5 participants