From 2619e382b7f5ac1fdf171e09159eb788743ab676 Mon Sep 17 00:00:00 2001 From: Devasheesh Kaul Date: Fri, 5 Sep 2025 15:26:12 +0530 Subject: [PATCH 1/2] feat: Add word break and soft hyphen inline formatting options --- .../format-library/src/default-formats.js | 3 + .../format-library/src/line-break/index.js | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 packages/format-library/src/line-break/index.js diff --git a/packages/format-library/src/default-formats.js b/packages/format-library/src/default-formats.js index 3ccfc92cb40c18..1bd7a3e057e1b6 100644 --- a/packages/format-library/src/default-formats.js +++ b/packages/format-library/src/default-formats.js @@ -15,6 +15,7 @@ import { keyboard } from './keyboard'; import { unknown } from './unknown'; import { language } from './language'; import { nonBreakingSpace } from './non-breaking-space'; +import { lineBreakWbr, softHyphen } from './line-break'; export default [ bold, @@ -31,4 +32,6 @@ export default [ unknown, language, nonBreakingSpace, + lineBreakWbr, + softHyphen, ]; diff --git a/packages/format-library/src/line-break/index.js b/packages/format-library/src/line-break/index.js new file mode 100644 index 00000000000000..6ddae817a9401d --- /dev/null +++ b/packages/format-library/src/line-break/index.js @@ -0,0 +1,58 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { insert, insertObject } from '@wordpress/rich-text'; +import { RichTextToolbarButton } from '@wordpress/block-editor'; +import { keyboardReturn, lineDashed } from '@wordpress/icons'; + +const nameWbr = 'core/line-break-wbr'; +const titleWbr = __( 'Insert word break' ); + +export const lineBreakWbr = { + name: nameWbr, + title: titleWbr, + tagName: 'wbr', + object: true, + className: 'wp-inline-wbr', + edit( { value, onChange, onFocus } ) { + const onClick = () => { + onChange( insertObject( value, { type: nameWbr } ) ); + onFocus(); + }; + + return ( + + ); + }, +}; + +const nameShy = 'core/soft-hyphen'; +const titleShy = __( 'Insert soft hyphen' ); + +export const softHyphen = { + name: nameShy, + title: titleShy, + tagName: 'span', + className: 'is-soft-hyphen-format', + edit( { value, onChange, onFocus } ) { + const onClick = () => { + onChange( insert( value, '\u00AD' ) ); + onFocus(); + }; + + return ( + + ); + }, +}; From f1b05b743a4aeb72cec40f3e311ad806571aa342 Mon Sep 17 00:00:00 2001 From: Devasheesh Kaul Date: Fri, 5 Sep 2025 18:52:30 +0530 Subject: [PATCH 2/2] refactor: change title name --- packages/format-library/src/line-break/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/format-library/src/line-break/index.js b/packages/format-library/src/line-break/index.js index 6ddae817a9401d..fca251382bd44c 100644 --- a/packages/format-library/src/line-break/index.js +++ b/packages/format-library/src/line-break/index.js @@ -7,7 +7,7 @@ import { RichTextToolbarButton } from '@wordpress/block-editor'; import { keyboardReturn, lineDashed } from '@wordpress/icons'; const nameWbr = 'core/line-break-wbr'; -const titleWbr = __( 'Insert word break' ); +const titleWbr = __( 'Word break' ); export const lineBreakWbr = { name: nameWbr, @@ -24,7 +24,7 @@ export const lineBreakWbr = { return ( @@ -33,7 +33,7 @@ export const lineBreakWbr = { }; const nameShy = 'core/soft-hyphen'; -const titleShy = __( 'Insert soft hyphen' ); +const titleShy = __( 'Soft hyphen' ); export const softHyphen = { name: nameShy,