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 restoreContentAndSplit #7618

Merged
merged 2 commits into from
Jul 19, 2018
Merged
Changes from all commits
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
21 changes: 4 additions & 17 deletions editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ export class RichText extends Component {
const before = domToFormat( beforeNodes, format, this.editor );
const after = domToFormat( afterNodes, format, this.editor );

this.restoreContentAndSplit( before, after );
this.props.onSplit( before, after );
} else {
event.preventDefault();

Expand Down Expand Up @@ -633,8 +633,8 @@ export class RichText extends Component {
afterRange.setStart( selectionRange.endContainer, selectionRange.endOffset );
afterRange.setEnd( rootNode, dom.nodeIndex( rootNode.lastChild ) + 1 );

const beforeFragment = beforeRange.extractContents();
const afterFragment = afterRange.extractContents();
const beforeFragment = beforeRange.cloneContents();
const afterFragment = afterRange.cloneContents();
Copy link
Member

Choose a reason for hiding this comment

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

Could the afterFragment still be extracted, so we can avoid having to set it afterwards? I think this this happens in the block edit component. Or maybe I'm misunderstanding this.

Copy link
Member Author

Choose a reason for hiding this comment

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

so we can avoid having to set it afterwards?

What do you mean by set?

Copy link
Member

Choose a reason for hiding this comment

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

By means of setAttributes in the block edit function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Still not totally sure I understand, but we should want the explicit setAttributes and avoid leveraging any of these more implicit DOM mutations.


const { format } = this.props;
before = domToFormat( filterEmptyNodes( beforeFragment.childNodes ), format, this.editor );
Expand Down Expand Up @@ -662,7 +662,7 @@ export class RichText extends Component {
after = this.isEmpty( after ) ? null : after;
}

this.restoreContentAndSplit( before, after, blocks );
onSplit( before, after, ...blocks );
}

onNodeChange( { parents } ) {
Expand Down Expand Up @@ -824,19 +824,6 @@ export class RichText extends Component {
} ) );
}

/**
* Calling onSplit means we need to abort the change done by TinyMCE.
* we need to call updateContent to restore the initial content before calling onSplit.
*
* @param {Array} before content before the split position
* @param {Array} after content after the split position
* @param {?Array} blocks blocks to insert at the split position
*/
restoreContentAndSplit( before, after, blocks = [] ) {
this.setContent( this.props.value );
this.props.onSplit( before, after, ...blocks );
}

render() {
const {
tagName: Tagname = 'div',
Expand Down