Skip to content

Commit

Permalink
Restore displaying formatting shortcuts in toolbar (#11104)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Oct 26, 2018
1 parent 95a02b9 commit 0a1d6e0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/editor/src/components/rich-text/format-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Component, Fragment } from '@wordpress/element';
import { getActiveFormat, getFormatTypes } from '@wordpress/rich-text';
import { Fill, KeyboardShortcuts, ToolbarButton } from '@wordpress/components';
import { rawShortcut } from '@wordpress/keycodes';
import { rawShortcut, displayShortcut } from '@wordpress/keycodes';

/**
* Internal dependencies
Expand All @@ -18,10 +18,19 @@ function isResult( { title, keywords = [] }, filterValue ) {
return matchSearch( title ) || keywords.some( matchSearch );
}

function FillToolbarButton( { name, ...props } ) {
function FillToolbarButton( { name, shortcutType, shortcutCharacter, ...props } ) {
let shortcut;

if ( shortcutType && shortcutCharacter ) {
shortcut = displayShortcut[ shortcutType ]( shortcutCharacter );
}

return (
<Fill name={ `RichText.ToolbarControls.${ name }` }>
<ToolbarButton { ...props } />
<ToolbarButton
{ ...props }
shortcut={ shortcut }
/>
</Fill>
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/format-library/src/bold/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const bold = {
title={ __( 'Bold' ) }
onClick={ onToggle }
isActive={ isActive }
shortcutType="primary"
shortcutCharacter="b"
/>
</Fragment>
);
Expand Down
2 changes: 2 additions & 0 deletions packages/format-library/src/italic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const italic = {
title={ __( 'Italic' ) }
onClick={ onToggle }
isActive={ isActive }
shortcutType="primary"
shortcutCharacter="i"
/>
</Fragment>
);
Expand Down
4 changes: 4 additions & 0 deletions packages/format-library/src/link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,17 @@ export const link = {
title={ __( 'Unlink' ) }
onClick={ this.onRemoveFormat }
isActive={ isActive }
shortcutType="primaryShift"
shortcutCharacter="k"
/> }
{ ! isActive && <ToolbarButton
name="link"
icon="admin-links"
title={ __( 'Link' ) }
onClick={ this.addLink }
isActive={ isActive }
shortcutType="primary"
shortcutCharacter="k"
/> }
<InlineLinkUI
addingLink={ this.state.addingLink }
Expand Down
2 changes: 2 additions & 0 deletions packages/format-library/src/strikethrough/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const strikethrough = {
title={ __( 'Strikethrough' ) }
onClick={ onToggle }
isActive={ isActive }
shortcutType="access"
shortcutCharacter="d"
/>
</Fragment>
);
Expand Down

0 comments on commit 0a1d6e0

Please sign in to comment.