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

Editor: Ignore save edit in undo history. #17452

Merged
merged 6 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Editor: Ignore save edits in undo history.
  • Loading branch information
epiqueras committed Sep 16, 2019
commit e8f75f77f5e9afaa8f07de1130f353ad26b7a46d
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