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

Experiment with adding undo/redo #15

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Experiment with adding undo/redo #15

wants to merge 11 commits into from

Conversation

getdave
Copy link
Owner

@getdave getdave commented Sep 15, 2020

As requested in this #6 this PR shows a PoC for adding undo/redo functionality to the standalone editor.

It's far from perfect as the real undo/redo functionality in the Post editor is more sophisticated and accounts for more scenarios.

That said it works at a basic level and should act as a good kicking off point.

Screen Capture on 2020-09-15 at 15-49-33



export const getBlocks = ( state ) => {
return state.present.blocks || [];
Copy link
Contributor

Choose a reason for hiding this comment

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

I've updated this to allow for a default/fallback set of blocks, so that can reload blocks previously worked on;

export const getBlocks = ( state, defaultBlocks=[] ) => {
	return state.present.blocks || defaultBlocks;
}
  const blocks = useSelect((select) => select("getdavesbe").getBlocks(parse(storedBlocks)));

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yep although grabbing for storage is a side effect so should probably be handled in a control action. Still working that one out.

@getdave
Copy link
Owner Author

getdave commented Oct 8, 2021

Still need to fix things so minor undo levels aren't created.

Isolated Block Editor uses different actions to control the behaviour here. I need to look into this

https://github.com/Automattic/isolated-block-editor/blob/82b69eda507554c76b4afecc1f75987955c22e36/src/components/block-editor-contents/index.js#L91-L92

@getdave getdave mentioned this pull request Oct 8, 2021
11 tasks
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.

2 participants