Skip to content

Commit

Permalink
switch back to blocking gutenberg undo altogether when classic block …
Browse files Browse the repository at this point in the history
…focused
  • Loading branch information
Glen Davies committed Jun 29, 2020
1 parent 18410e5 commit d7ab8bc
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions packages/block-library/src/classic/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default class ClassicEdit extends Component {
this.initialize = this.initialize.bind( this );
this.onSetup = this.onSetup.bind( this );
this.focus = this.focus.bind( this );
this.state = { lastUndo: false };
}

componentDidMount() {
Expand Down Expand Up @@ -138,7 +137,8 @@ export default class ClassicEdit extends Component {

editor.on( 'keydown', ( event ) => {
if ( isKeyboardEvent.primary( event, 'z' ) ) {
this.handleUndo( event );
// Prevent the gutenberg undo kicking in so TinyMCE undo stack works as expected
event.stopPropagation();
}

if (
Expand Down Expand Up @@ -215,19 +215,6 @@ export default class ClassicEdit extends Component {
event.nativeEvent.stopImmediatePropagation();
}

handleUndo( event ) {
// While there is content in the block prevent Gutenberg undo from kicking in so TinyMCE undo stack works.
// Need to also track if it is the last undo otherwise block is removed along with last bit of content.
if ( isTmceEmpty( this.editor ) && ! this.state.lastUndo ) {
this.setState( { lastUndo: true } );
event.stopPropagation();
}
if ( ! isTmceEmpty( this.editor ) ) {
this.setState( { lastUndo: false } );
event.stopPropagation();
}
}

render() {
const { clientId } = this.props;

Expand Down

0 comments on commit d7ab8bc

Please sign in to comment.