Skip to content

Commit

Permalink
Format Library: Add keyboard shortcut for inline code (WordPress#41816)
Browse files Browse the repository at this point in the history
* Format Library: Add keyboard shortcut for inline code
* Update KeyboardShortcuts help modal
* Update snapshots
  • Loading branch information
Mamaduka authored Jun 22, 2022
1 parent 0f97e8d commit ca3f229
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ export const textFormattingShortcuts = [
keyCombination: { modifier: 'primary', character: 'u' },
description: __( 'Underline the selected text.' ),
},
{
keyCombination: { modifier: 'access', character: 'x' },
description: __( 'Make the selected text inline code.' ),
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ exports[`KeyboardShortcutHelpModal should match snapshot when the modal is activ
"modifier": "primary",
},
},
Object {
"description": "Make the selected text inline code.",
"keyCombination": Object {
"character": "x",
"modifier": "access",
},
},
]
}
title="Text formatting"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ export const textFormattingShortcuts = [
keyCombination: { modifier: 'primary', character: 'u' },
description: __( 'Underline the selected text.' ),
},
{
keyCombination: { modifier: 'access', character: 'x' },
description: __( 'Make the selected text inline code.' ),
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ export const textFormattingShortcuts = [
keyCombination: { modifier: 'primary', character: 'u' },
description: __( 'Underline the selected text.' ),
},
{
keyCombination: { modifier: 'access', character: 'x' },
description: __( 'Make the selected text inline code.' ),
},
];
26 changes: 18 additions & 8 deletions packages/format-library/src/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*/
import { __ } from '@wordpress/i18n';
import { toggleFormat, remove, applyFormat } from '@wordpress/rich-text';
import { RichTextToolbarButton } from '@wordpress/block-editor';
import {
RichTextToolbarButton,
RichTextShortcut,
} from '@wordpress/block-editor';
import { code as codeIcon } from '@wordpress/icons';

const name = 'core/code';
Expand Down Expand Up @@ -51,13 +54,20 @@ export const code = {
}

return (
<RichTextToolbarButton
icon={ codeIcon }
title={ title }
onClick={ onClick }
isActive={ isActive }
role="menuitemcheckbox"
/>
<>
<RichTextShortcut
type="access"
character="x"
onUse={ onClick }
/>
<RichTextToolbarButton
icon={ codeIcon }
title={ title }
onClick={ onClick }
isActive={ isActive }
role="menuitemcheckbox"
/>
</>
);
},
};

0 comments on commit ca3f229

Please sign in to comment.