From 484248ba353e4f71974eb34a5f3e4a8e463fd35d Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 5 Jan 2021 17:20:04 +0100 Subject: [PATCH] Fix undo --- packages/core-data/src/entity-provider.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/core-data/src/entity-provider.js b/packages/core-data/src/entity-provider.js index 6f64e803194e2f..1c772014a4051b 100644 --- a/packages/core-data/src/entity-provider.js +++ b/packages/core-data/src/entity-provider.js @@ -155,8 +155,8 @@ export function useEntityBlockEditor( kind, type, { id: _id } = {} ) { useEffect( () => { // Load the blocks from the content if not already in state // Guard against other instances that might have - // set content to a function already. - if ( content && typeof content !== 'function' ) { + // set content to a function already or the blocks are already in state. + if ( content && typeof content !== 'function' && ! blocks ) { const parsedContent = parse( content ); editEntityRecord( kind, @@ -174,6 +174,7 @@ export function useEntityBlockEditor( kind, type, { id: _id } = {} ) { ( newBlocks, options ) => { const { selectionStart, selectionEnd } = options; const edits = { blocks: newBlocks, selectionStart, selectionEnd }; + const noChange = blocks === edits.blocks; if ( noChange ) { return __unstableCreateUndoLevel( kind, type, id ); @@ -187,16 +188,14 @@ export function useEntityBlockEditor( kind, type, { id: _id } = {} ) { editEntityRecord( kind, type, id, edits ); }, - [ blocks, id, type, kind ] + [ kind, type, id, blocks ] ); const onInput = useCallback( ( newBlocks, options ) => { const { selectionStart, selectionEnd } = options; const edits = { blocks: newBlocks, selectionStart, selectionEnd }; - editEntityRecord( kind, type, id, edits, { - undoIgnore: true, - } ); + editEntityRecord( kind, type, id, edits ); }, [ kind, type, id ] );