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

Rich Text: Remove updateContent function #7620

Merged
merged 3 commits into from
Jul 3, 2018
Merged
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
17 changes: 3 additions & 14 deletions editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,20 +695,9 @@ export class RichText extends Component {
}
}

updateContent() {
// Do not trigger a change event coming from the TinyMCE undo manager.
// Our global state is already up-to-date.
this.editor.undoManager.ignore( () => {
const bookmark = this.editor.selection.getBookmark( 2, true );

this.savedContent = this.props.value;
this.setContent( this.savedContent );
this.editor.selection.moveToBookmark( bookmark );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Dropping the focus management breaks the "merge". The focus is not restored at the right position when merging two paragraphs.

  • I believe the undo behavior is also necessary in this case or in cases the value of a RichText is updated programmatically (the change is not triggered by the RichText element itself)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But all tests have passed successfully!

😉

Copy link
Contributor

@youknowriad youknowriad Jun 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahaha :) we definitely need a test for that. I guess we only test the content and not the cursor position.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a failing test in dd0e347.

} );
}

setContent( content ) {
const { format } = this.props;
this.savedContent = content;
this.editor.setContent( valueToString( content, format ) );
}

Expand Down Expand Up @@ -739,7 +728,7 @@ export class RichText extends Component {
! isEqual( this.props.value, prevProps.value ) &&
! isEqual( this.props.value, this.savedContent )
) {
this.updateContent();
this.setContent( this.props.value );
}

if ( 'development' === process.env.NODE_ENV ) {
Expand Down Expand Up @@ -829,7 +818,7 @@ export class RichText extends Component {
* @param {?Array} blocks blocks to insert at the split position
*/
restoreContentAndSplit( before, after, blocks = [] ) {
this.updateContent();
this.setContent( this.props.value );
this.props.onSplit( before, after, ...blocks );
}

Expand Down