Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 9, 2019
1 parent 00e9eb0 commit 136dd3c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
16 changes: 8 additions & 8 deletions packages/editor/src/components/rich-text/list-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Toolbar } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
import {
applyLineFormat,
removeLineFormat,
indentListItems,
outdentListItems,
} from '@wordpress/rich-text';

/**
Expand Down Expand Up @@ -52,28 +52,28 @@ export const ListEdit = ( {
type="primary"
character="["
onUse={ () => {
onChange( removeLineFormat( value ) );
onChange( outdentListItems( value ) );
} }
/>
<RichTextShortcut
type="primary"
character="]"
onUse={ () => {
onChange( applyLineFormat( value, { type: tagName } ) );
onChange( indentListItems( value, { type: tagName } ) );
} }
/>
<RichTextShortcut
type="primary"
character="m"
onUse={ () => {
onChange( applyLineFormat( value, { type: tagName } ) );
onChange( indentListItems( value, { type: tagName } ) );
} }
/>
<RichTextShortcut
type="primaryShift"
character="m"
onUse={ () => {
onChange( removeLineFormat( value ) );
onChange( outdentListItems( value ) );
} }
/>
<BlockFormatControls>
Expand Down Expand Up @@ -109,14 +109,14 @@ export const ListEdit = ( {
icon: 'editor-outdent',
title: __( 'Outdent list item' ),
onClick: () => {
onChange( removeLineFormat( value ) );
onChange( outdentListItems( value ) );
},
},
{
icon: 'editor-indent',
title: __( 'Indent list item' ),
onClick: () => {
onChange( applyLineFormat( value, { type: tagName } ) );
onChange( indentListItems( value, { type: tagName } ) );
},
},
].filter( Boolean ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getTargetFormats(
return [];
}

export function applyLineFormat( value, rootFormat ) {
export function indentListItems( value, rootFormat ) {
const lineIndex = getLineIndex( value );

if ( lineIndex === undefined ) {
Expand Down
4 changes: 2 additions & 2 deletions packages/rich-text/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import './store';

export { applyFormat } from './apply-format';
export { applyLineFormat } from './apply-line-format';
export { charAt } from './char-at';
export { concat } from './concat';
export { create } from './create';
Expand All @@ -14,7 +13,6 @@ export { isEmpty, isEmptyLine } from './is-empty';
export { join } from './join';
export { registerFormatType } from './register-format-type';
export { removeFormat } from './remove-format';
export { removeLineFormat } from './remove-line-format';
export { remove } from './remove';
export { replace } from './replace';
export { insert } from './insert';
Expand All @@ -27,3 +25,5 @@ export { toHTMLString } from './to-html-string';
export { toggleFormat } from './toggle-format';
export { LINE_SEPARATOR } from './special-characters';
export { unregisterFormatType } from './unregister-format-type';
export { indentListItems } from './indent-list-items';
export { outdentListItems } from './outdent-list-items';
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function getParentFormats( { text, formats }, startIndex, formatCount ) {
return [];
}

export function removeLineFormat( value ) {
export function outdentListItems( value ) {
const { text, formats, start, end } = value;
const lineIndex = getLineIndex( value );
const lineFormats = formats[ lineIndex ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import deepFreeze from 'deep-freeze';
* Internal dependencies
*/

import { applyLineFormat } from '../apply-line-format';
import { indentListItems } from '../indent-list-items';
import { getSparseArrayLength } from './helpers';
import { LINE_SEPARATOR } from '../special-characters';

describe( 'applyFormat', () => {
const ul = { type: 'ul' };
const ol = { type: 'ol' };

it( 'should not apply anything if there is only one line', () => {
it( 'should not indent only item', () => {
const record = {
formats: [ , ],
text: '1',
start: 1,
end: 1,
};
const result = applyLineFormat( deepFreeze( record ), ul );
const result = indentListItems( deepFreeze( record ), ul );

expect( result ).toEqual( record );
expect( result ).toBe( record );
expect( getSparseArrayLength( result.formats ) ).toBe( 0 );
} );

it( 'should apply line format', () => {
it( 'should indent', () => {
const record = {
formats: [ , , ],
text: `1${ LINE_SEPARATOR }`,
Expand All @@ -42,28 +42,28 @@ describe( 'applyFormat', () => {
start: 2,
end: 2,
};
const result = applyLineFormat( deepFreeze( record ), ul );
const result = indentListItems( deepFreeze( record ), ul );

expect( result ).toEqual( expected );
expect( result ).not.toBe( record );
expect( getSparseArrayLength( result.formats ) ).toBe( 1 );
} );

it( 'should not apply additional line format', () => {
it( 'should not indent without target list', () => {
const record = {
formats: [ , [ ul ] ],
text: `1${ LINE_SEPARATOR }`,
start: 2,
end: 2,
};
const result = applyLineFormat( deepFreeze( record ), ul );
const result = indentListItems( deepFreeze( record ), ul );

expect( result ).toEqual( record );
expect( result ).toBe( record );
expect( getSparseArrayLength( result.formats ) ).toBe( 1 );
} );

it( 'should apply line format with previous line format', () => {
it( 'should indent and merge with previous list', () => {
const record = {
formats: [ , [ ol ], , ],
text: `1${ LINE_SEPARATOR }${ LINE_SEPARATOR }`,
Expand All @@ -76,14 +76,14 @@ describe( 'applyFormat', () => {
start: 3,
end: 3,
};
const result = applyLineFormat( deepFreeze( record ), ul );
const result = indentListItems( deepFreeze( record ), ul );

expect( result ).toEqual( expected );
expect( result ).not.toBe( record );
expect( getSparseArrayLength( result.formats ) ).toBe( 2 );
} );

it( 'should apply line format with existing', () => {
it( 'should indent already indented item', () => {
const record = {
formats: [ , [ ul ], , [ ul ], , ],
text: `1${ LINE_SEPARATOR }2${ LINE_SEPARATOR }3`,
Expand All @@ -96,14 +96,14 @@ describe( 'applyFormat', () => {
start: 5,
end: 5,
};
const result = applyLineFormat( deepFreeze( record ), ul );
const result = indentListItems( deepFreeze( record ), ul );

expect( result ).toEqual( expected );
expect( result ).not.toBe( record );
expect( getSparseArrayLength( result.formats ) ).toBe( 2 );
} );

it( 'should apply line format with multi select', () => {
it( 'should indent with multiple lines selected', () => {
const record = {
formats: [ , , , [ ul ], , ],
text: `1${ LINE_SEPARATOR }2${ LINE_SEPARATOR }3`,
Expand All @@ -116,7 +116,7 @@ describe( 'applyFormat', () => {
start: 2,
end: 5,
};
const result = applyLineFormat( deepFreeze( record ), ul );
const result = indentListItems( deepFreeze( record ), ul );

expect( result ).toEqual( expected );
expect( result ).not.toBe( record );
Expand Down

0 comments on commit 136dd3c

Please sign in to comment.