Skip to content

Commit

Permalink
Fix selection accumulation after ba37dca
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 29, 2018
1 parent 64ec102 commit a7116e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ export class RichText extends Component {
this.onChange( newValue );

event.preventDefault();
// TinyMCE won't stop on `preventDefault`.
// It's important that we stop other handlers (e.g. ones
// registered by TinyMCE) from also handling this event.
event.stopImmediatePropagation();
}
}
Expand All @@ -638,6 +639,9 @@ export class RichText extends Component {
// We also split the content and call the onSplit prop if provided.
if ( keyCode === ENTER ) {
event.preventDefault();
// It's important that we stop other handlers (e.g. ones registered
// by TinyMCE) from also handling this event.
event.stopImmediatePropagation();

const record = this.createRecord();

Expand All @@ -648,10 +652,6 @@ export class RichText extends Component {
} );

if ( transformation ) {
// Calling onReplace() will destroy the editor, so it's
// important that we stop other handlers (e.g. ones
// registered by TinyMCE) from also handling this event.
event.stopImmediatePropagation();
this.props.onReplace( [
transformation.transform( { content: text } ),
] );
Expand Down
11 changes: 11 additions & 0 deletions packages/rich-text/src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,18 @@ function createFromMultilineElement( {
// If a line consists of one single line break (invisible), consider the
// line empty, wether this is the browser's doing or not.
if ( value.text === '\n' ) {
const start = value.start;
const end = value.end;

value = createEmptyValue();

if ( start !== undefined ) {
value.start = 0;
}

if ( end !== undefined ) {
value.end = 0;
}
}

// Multiline value text should be separated by a double line break.
Expand Down

0 comments on commit a7116e1

Please sign in to comment.