Skip to content

Commit

Permalink
Include diff missed by previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hypest committed Apr 4, 2019
1 parent 9dcd23b commit fd62f01
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
18 changes: 12 additions & 6 deletions packages/block-editor/src/components/rich-text/list-edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Toolbar } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import {
changeListType,
getStartNestingLevel,
getStartListFormat,
} from '@wordpress/rich-text';

/**
Expand All @@ -22,7 +22,7 @@ import BlockFormatControls from '../block-format-controls';
* inner list is selected.
*/
function isListRootSelected( value ) {
return getStartNestingLevel( value ) < 1;
return getStartListFormat( value ).nestingLevel < 1;
}

/**
Expand All @@ -34,8 +34,14 @@ function isListRootSelected( value ) {
*
* @return {boolean} [description]
*/
function isActiveListType( tagName, rootTagName ) {
return tagName === rootTagName;
function isActiveListType( tagName, rootTagName, value ) {
const listFormat = getStartListFormat( value );

if ( ! listFormat || ! listFormat.type ) {
return tagName === rootTagName;
}

return listFormat.type.toLowerCase() === tagName;
}

export const ListEdit = ( {
Expand All @@ -50,7 +56,7 @@ export const ListEdit = ( {
onTagNameChange && {
icon: 'editor-ul',
title: __( 'Convert to unordered list' ),
isActive: isActiveListType( 'ul', tagName ),
isActive: isActiveListType( 'ul', tagName, value ),
onClick() {
onChange( changeListType( value, { type: 'ul' } ) );

Expand All @@ -62,7 +68,7 @@ export const ListEdit = ( {
onTagNameChange && {
icon: 'editor-ol',
title: __( 'Convert to ordered list' ),
isActive: isActiveListType( 'ol', tagName ),
isActive: isActiveListType( 'ol', tagName, value ),
onClick() {
onChange( changeListType( value, { type: 'ol' } ) );

Expand Down
4 changes: 2 additions & 2 deletions packages/rich-text/src/get-start-list-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export function getStartListFormat( value ) {
const { text, replacements, start, end } = value;
const startingLineIndex = getLineIndex( value, start );
const startLineFormats = replacements[ startingLineIndex ] || [];
const listFormat = startLineFormats.slice( -1 );
return { nestingLevel: startLineFormats.length, listFormat };
const [ listFormat ] = startLineFormats.slice( -1 );
return { nestingLevel: startLineFormats.length, ...listFormat };
}
2 changes: 1 addition & 1 deletion packages/rich-text/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export { getActiveObject } from './get-active-object';
export { getSelectionEnd } from './get-selection-end';
export { getSelectionStart } from './get-selection-start';
export { getTextContent } from './get-text-content';
export { getStartNestingLevel } from './get-start-nesting-level';
export { getStartListFormat } from './get-start-list-format';
export { isCollapsed } from './is-collapsed';
export { isEmpty, isEmptyLine } from './is-empty';
export { join } from './join';
Expand Down

0 comments on commit fd62f01

Please sign in to comment.