Skip to content

Commit

Permalink
Underline text when cmd + u is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Dec 27, 2018
1 parent 7ea5021 commit 6428563
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/format-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { image } from './image';
import { italic } from './italic';
import { link } from './link';
import { strikethrough } from './strikethrough';
import { underline } from './underline';

/**
* WordPress dependencies
Expand All @@ -22,4 +23,5 @@ import {
italic,
link,
strikethrough,
underline,
].forEach( ( { name, ...settings } ) => registerFormatType( name, settings ) );
38 changes: 38 additions & 0 deletions packages/format-library/src/underline/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
import { toggleFormat } from '@wordpress/rich-text';
import { RichTextToolbarButton, RichTextShortcut } from '@wordpress/editor';

const name = 'core/underline';

export const underline = {
name,
title: __( 'Underline' ),
tagName: 'u',
className: null,
edit( { isActive, value, onChange } ) {
const onToggle = () => onChange( toggleFormat( value, { type: name } ) );

return (
<Fragment>
<RichTextShortcut
type="primary"
character="u"
onUse={ onToggle }
/>
<RichTextToolbarButton
name="underline"
icon="editor-underline"
title={ __( 'Underline' ) }
onClick={ onToggle }
isActive={ isActive }
shortcutType="primary"
shortcutCharacter="u"
/>
</Fragment>
);
},
};

0 comments on commit 6428563

Please sign in to comment.