From 1adfe8d3cb3a9b5b66317ed293ef881ee1090b66 Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Mon, 12 Feb 2024 12:05:17 +0100 Subject: [PATCH] Revert "Rich text: pad multiple spaces through en/em replacement (#56341)" (#58792) This reverts commit 53cae01b5de913779005bb7eaa5fd010555bf01c. Co-authored-by: ellatrix Co-authored-by: jeryj Co-authored-by: t-hamano Co-authored-by: dmsnell --- .../components/rich-text/use-input-rules.js | 32 ++----------------- test/e2e/specs/editor/blocks/links.spec.js | 4 +-- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/use-input-rules.js b/packages/block-editor/src/components/rich-text/use-input-rules.js index 37e61997f14986..ff871eb9363234 100644 --- a/packages/block-editor/src/components/rich-text/use-input-rules.js +++ b/packages/block-editor/src/components/rich-text/use-input-rules.js @@ -3,7 +3,7 @@ */ import { useRef } from '@wordpress/element'; import { useRefEffect } from '@wordpress/compose'; -import { insert, isCollapsed, toHTMLString } from '@wordpress/rich-text'; +import { insert, toHTMLString } from '@wordpress/rich-text'; import { getBlockTransforms, findTransform } from '@wordpress/blocks'; import { useDispatch } from '@wordpress/data'; @@ -47,34 +47,6 @@ function findSelection( blocks ) { return []; } -/** - * An input rule that replaces two spaces with an en space, and an en space - * followed by a space with an em space. - * - * @param {Object} value Value to replace spaces in. - * - * @return {Object} Value with spaces replaced. - */ -function replacePrecedingSpaces( value ) { - if ( ! isCollapsed( value ) ) { - return value; - } - - const { text, start } = value; - const lastTwoCharacters = text.slice( start - 2, start ); - - // Replace two spaces with an em space. - if ( lastTwoCharacters === ' ' ) { - return insert( value, '\u2002', start - 2, start ); - } - // Replace an en space followed by a space with an em space. - else if ( lastTwoCharacters === '\u2002 ' ) { - return insert( value, '\u2003', start - 2, start ); - } - - return value; -} - export function useInputRules( props ) { const { __unstableMarkLastChangeAsPersistent, @@ -155,7 +127,7 @@ export function useInputRules( props ) { return accumlator; }, - preventEventDiscovery( replacePrecedingSpaces( value ) ) + preventEventDiscovery( value ) ); if ( transformed !== value ) { diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 0a95064032f832..d0689cabd7e6b0 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -1026,8 +1026,8 @@ test.describe( 'Links', () => { pageUtils, editor, } ) => { - const textToSelect = `\u2003\u2003 spaces\u2003 `; - const textWithWhitespace = `Text with leading and trailing spaces `; + const textToSelect = ` spaces `; + const textWithWhitespace = `Text with leading and trailing${ textToSelect }`; // Create a block with some text. await editor.insertBlock( {