Skip to content

Commit

Permalink
Underline text when cmd + u is pressed (#13117)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored Jan 15, 2019
1 parent ec1176d commit 69a336f
Show file tree
Hide file tree
Showing 2 changed files with 42 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 ) );
40 changes: 40 additions & 0 deletions packages/format-library/src/underline/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
import { toggleFormat } from '@wordpress/rich-text';
import { RichTextShortcut } from '@wordpress/editor';

const name = 'core/underline';

export const underline = {
name,
title: __( 'Underline' ),
tagName: 'span',
className: null,
attributes: {
style: 'style',
},
edit( { value, onChange } ) {
const onToggle = () => {
onChange(
toggleFormat( value, {
type: name,
attributes: {
style: 'text-decoration: underline;',
},
} ) );
};

return (
<Fragment>
<RichTextShortcut
type="primary"
character="u"
onUse={ onToggle }
/>
</Fragment>
);
},
};

0 comments on commit 69a336f

Please sign in to comment.