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

RichText: don't set selection during selectionchange #13896

Merged
merged 2 commits into from
Feb 15, 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
5 changes: 3 additions & 2 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,14 @@ export class RichText extends Component {
} );
}

applyRecord( record ) {
applyRecord( record, { domOnly } = {} ) {
apply( {
value: record,
current: this.editableRef,
multilineTag: this.multilineTag,
multilineWrapperTags: this.multilineWrapperTags,
prepareEditableTree: this.props.prepareEditableTree,
__unstableDomOnly: domOnly,
Copy link
Member

Choose a reason for hiding this comment

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

Part of me wonders if this is the sort of thing where it'd be easier to just pass through whatever additional options verbatim, i.e. ...options from a second object argument. But I can also see the opposite argument of there being value in being explicit, especially in this case where it's something perhaps temporary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I definitely see this as something temporary.

} );
}

Expand Down Expand Up @@ -421,7 +422,7 @@ export class RichText extends Component {
}

this.setState( { start, end, selectedFormat } );
this.applyRecord( { ...value, selectedFormat } );
this.applyRecord( { ...value, selectedFormat }, { domOnly: true } );

delete this.formatPlaceholder;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/rich-text/src/to-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export function apply( {
multilineTag,
multilineWrapperTags,
prepareEditableTree,
__unstableDomOnly,
} ) {
// Construct a new element tree in memory.
const { body, selection } = toDom( {
Expand All @@ -223,7 +224,7 @@ export function apply( {

applyValue( body, current );

if ( value.start !== undefined ) {
if ( value.start !== undefined && ! __unstableDomOnly ) {
applySelection( selection, current );
}
}
Expand Down