Skip to content

Commit

Permalink
RichText: add non breaking space shortcut on Windows (#43150)
Browse files Browse the repository at this point in the history
Unlinked contributors: rezeau, pierrefrance, burnuser, zackkatz.

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: yankiara <[email protected]>
Co-authored-by: tybor <[email protected]>
Co-authored-by: fr-laurentn <[email protected]>
Co-authored-by: TonyGravagno <[email protected]>
Co-authored-by: noisysocks <[email protected]>
Co-authored-by: benjaminpwarren <[email protected]>
  • Loading branch information
9 people authored Mar 20, 2024
1 parent cef411c commit 810e49d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ export const textFormattingShortcuts = [
'Convert the current paragraph or heading to a heading of level 1 to 6.'
),
},
{
keyCombination: { modifier: 'primaryShift', character: 'SPACE' },
description: __( 'Add non breaking space.' ),
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ export const textFormattingShortcuts = [
'Convert the current paragraph or heading to a heading of level 1 to 6.'
),
},
{
keyCombination: { modifier: 'primaryShift', character: '\u00a0' },
description: __( 'Add non breaking space.' ),
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ export const textFormattingShortcuts = [
'Convert the current paragraph or heading to a heading of level 1 to 6.'
),
},
{
keyCombination: { modifier: 'primaryShift', character: 'SPACE' },
description: __( 'Add non breaking space.' ),
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ export const textFormattingShortcuts = [
'Convert the current paragraph or heading to a heading of level 1 to 6.'
),
},
{
keyCombination: { modifier: 'primaryShift', character: 'SPACE' },
description: __( 'Add non breaking space.' ),
},
];
2 changes: 2 additions & 0 deletions packages/format-library/src/default-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { superscript } from './superscript';
import { keyboard } from './keyboard';
import { unknown } from './unknown';
import { language } from './language';
import { nonBreakingSpace } from './non-breaking-space';

export default [
bold,
Expand All @@ -29,4 +30,5 @@ export default [
keyboard,
unknown,
language,
nonBreakingSpace,
];
29 changes: 29 additions & 0 deletions packages/format-library/src/non-breaking-space/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { insert } from '@wordpress/rich-text';
import { RichTextShortcut } from '@wordpress/block-editor';

const name = 'core/non-breaking-space';
const title = __( 'Non breaking space' );

export const nonBreakingSpace = {
name,
title,
tagName: 'nbsp',
className: null,
edit( { value, onChange } ) {
function addNonBreakingSpace() {
onChange( insert( value, '\u00a0' ) );
}

return (
<RichTextShortcut
type="primaryShift"
character=" "
onUse={ addNonBreakingSpace }
/>
);
},
};

0 comments on commit 810e49d

Please sign in to comment.