Skip to content

Commit

Permalink
WIP: make shift+enter work in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 28, 2019
1 parent 2bd701d commit 26be204
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,24 @@ export class RichText extends Component {
}

if ( this.multilineTag ) {
if ( this.onSplit && isEmptyLine( record ) ) {
if ( event.shiftKey ) {
const text = getTextContent( record );
const end = getSelectionEnd( record );
const length = text.length;
let toInsert = '\n';

// If the caret is at the end of the text, and there is no
// trailing line break or no text at all, we have to insert two
// line breaks in order to create a new line visually and place
// the caret there.
if ( ( end === length || charAt( record, end ) === LINE_SEPARATOR ) && (
text.charAt( end - 1 ) !== '\n' || length === 0
) ) {
toInsert = '\n\n';
}

this.onChange( insert( record, toInsert ) );
} else if ( this.onSplit && isEmptyLine( record ) ) {
this.onSplit( ...split( record ).map( this.valueToFormat ) );
} else {
this.onChange( insertLineSeparator( record ) );
Expand Down

0 comments on commit 26be204

Please sign in to comment.