Skip to content

Commit

Permalink
Editor: Ignore save edits in undo history.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Sep 16, 2019
1 parent b0606f7 commit e8f75f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 9 additions & 0 deletions packages/e2e-tests/specs/undo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ describe( 'undo', () => {
expect( visibleContent ).toBe( 'original' );
} );

it( 'should not create undo levels when saving', async () => {
await clickBlockAppender();
await page.keyboard.type( '1' );
await saveDraft();
await pressKeyWithModifier( 'primary', 'z' );

expect( await getEditedPostContent() ).toBe( '' );
} );

it( 'should immediately create an undo level on typing', async () => {
await clickBlockAppender();

Expand Down
17 changes: 13 additions & 4 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,22 @@ export function setupEditorState( post ) {
* Returns an action object used in signalling that attributes of the post have
* been edited.
*
* @param {Object} edits Post attributes to edit.
* @param {Object} edits Post attributes to edit.
* @param {boolean} undoIgnore Whether to ignore the edit in undo history or not.
*
* @yield {Object} Action object or control.
*/
export function* editPost( edits ) {
export function* editPost( edits, undoIgnore ) {
const { id, type } = yield select( STORE_KEY, 'getCurrentPost' );
yield dispatch( 'core', 'editEntityRecord', 'postType', type, id, edits );
yield dispatch(
'core',
'editEntityRecord',
'postType',
type,
id,
edits,
undoIgnore
);
}

/**
Expand Down Expand Up @@ -385,7 +394,7 @@ export function* savePost( options = {} ) {
content: yield select( STORE_KEY, 'getEditedPostContent' ),
};
if ( ! options.isAutosave ) {
yield dispatch( STORE_KEY, 'editPost', edits );
yield dispatch( STORE_KEY, 'editPost', edits, true );
}

yield __experimentalRequestPostUpdateStart( options );
Expand Down

0 comments on commit e8f75f7

Please sign in to comment.