Skip to content

Commit

Permalink
Add inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Mar 13, 2019
1 parent c013263 commit 2888652
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,16 @@ export class RichText extends Component {
this.handleHorizontalNavigation( event );
}

// Use the space key in list items (at the start of an item) to indent
// the list item.
if ( keyCode === SPACE && this.multilineTag === 'li' ) {
const value = this.createRecord();

if ( isCollapsed( value ) ) {
const { text, start } = value;
const characterBefore = text[ start - 1 ];

// The caret must be at the start of a line.
if ( ! characterBefore || characterBefore === LINE_SEPARATOR ) {
this.onChange( indentListItems( value, { type: this.props.tagName } ) );
event.preventDefault();
Expand Down Expand Up @@ -634,7 +637,11 @@ export class RichText extends Component {
const index = start - 1;

if ( charAt( value, index ) === LINE_SEPARATOR ) {
if ( isCollapsed( value ) && formats[ index ] && formats[ index ].length ) {
const collapsed = isCollapsed( value );

// If the line separator that is about te be removed
// contains wrappers, remove the wrappers first.
if ( collapsed && formats[ index ] && formats[ index ].length ) {
const newFormats = formats.slice();

newFormats[ index ] = formats[ index ].slice( 0, -1 );
Expand All @@ -646,14 +653,18 @@ export class RichText extends Component {
newValue = remove(
value,
// Only remove the line if the selection is
// collapsed.
isCollapsed( value ) ? start - 1 : start,
// collapsed, otherwise remove the selection.
collapsed ? start - 1 : start,
end
);
}
}
} else if ( charAt( value, end ) === LINE_SEPARATOR ) {
if ( isCollapsed( value ) && formats[ end ] && formats[ end ].length ) {
const collapsed = isCollapsed( value );

// If the line separator that is about te be removed
// contains wrappers, remove the wrappers first.
if ( collapsed && formats[ end ] && formats[ end ].length ) {
const newFormats = formats.slice();

newFormats[ end ] = formats[ end ].slice( 0, -1 );
Expand All @@ -666,8 +677,8 @@ export class RichText extends Component {
value,
start,
// Only remove the line if the selection is
// collapsed.
isCollapsed( value ) ? end + 1 : end,
// collapsed, otherwise remove the selection.
collapsed ? end + 1 : end,
);
}
}
Expand Down

0 comments on commit 2888652

Please sign in to comment.