diff --git a/editor/components/editor-history/redo.js b/editor/components/editor-history/redo.js index 64457a35968ff0..9bfe2ab756f3ad 100644 --- a/editor/components/editor-history/redo.js +++ b/editor/components/editor-history/redo.js @@ -15,7 +15,7 @@ function EditorHistoryRedo( { hasRedo, redo } ) { shortcut={ displayShortcut.primaryShift( 'z' ) } disabled={ ! hasRedo } onClick={ redo } - className="editor-history__undo" + className="editor-history__redo" /> ); } diff --git a/editor/components/rich-text/index.js b/editor/components/rich-text/index.js index e8b2ef08096f61..62ccd90bd92296 100644 --- a/editor/components/rich-text/index.js +++ b/editor/components/rich-text/index.js @@ -513,8 +513,6 @@ export class RichText extends Component { return; } - this.onCreateUndoLevel(); - const forward = keyCode === DELETE; if ( this.props.onMerge ) { @@ -557,7 +555,6 @@ export class RichText extends Component { } event.preventDefault(); - this.onCreateUndoLevel(); const childNodes = Array.from( rootNode.childNodes ); const index = dom.nodeIndex( selectedNode ); @@ -571,7 +568,6 @@ export class RichText extends Component { this.restoreContentAndSplit( before, after ); } else { event.preventDefault(); - this.onCreateUndoLevel(); if ( event.shiftKey || ! this.props.onSplit ) { this.editor.execCommand( 'InsertLineBreak', false, event ); diff --git a/test/e2e/specs/undo.test.js b/test/e2e/specs/undo.test.js new file mode 100644 index 00000000000000..3f6e665e0045bf --- /dev/null +++ b/test/e2e/specs/undo.test.js @@ -0,0 +1,40 @@ +/** + * Internal dependencies + */ +import '../support/bootstrap'; +import { + newPost, + newDesktopBrowserPage, + pressWithModifier, + getHTMLFromCodeEditor, +} from '../support/utils'; + +describe( 'undo', () => { + beforeAll( async () => { + await newDesktopBrowserPage(); + await newPost(); + } ); + + it( 'Should undo to expected level intervals', async () => { + await page.click( '.editor-default-block-appender' ); + + await page.keyboard.type( 'This' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( 'is' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( 'test' ); + + await pressWithModifier( 'mod', 'z' ); // Strip 3rd paragraph text + await pressWithModifier( 'mod', 'z' ); // Strip 3rd paragraph block + await pressWithModifier( 'mod', 'z' ); // Strip 2nd paragraph text + await pressWithModifier( 'mod', 'z' ); // Strip 2nd paragraph block + await pressWithModifier( 'mod', 'z' ); // Strip 1st paragraph text + await pressWithModifier( 'mod', 'z' ); // Strip 1st paragraph block + + expect( await getHTMLFromCodeEditor() ).toBe( '' ); + + // Should have no more history. + const undoButton = await page.$( '.editor-history__undo:not( :disabled )' ); + expect( undoButton ).toBeNull(); + } ); +} );