From 320810302ea246fba9731d1d1d4a4769ec215018 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Thu, 30 Apr 2020 15:46:14 -0400 Subject: [PATCH] Remove willTrimSpacesCheck for Android --- .../rich-text/src/component/index.native.js | 36 +------------------ .../src/component/test/index.native.js | 34 ------------------ 2 files changed, 1 insertion(+), 69 deletions(-) delete mode 100644 packages/rich-text/src/component/test/index.native.js diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index ef95601dd80089..ac3c99a577782d 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -84,7 +84,6 @@ export class RichText extends Component { this ); this.valueToFormat = this.valueToFormat.bind( this ); - this.willTrimSpaces = this.willTrimSpaces.bind( this ); this.getHtmlToRender = this.getHtmlToRender.bind( this ); this.state = { activeFormats: [], @@ -631,29 +630,6 @@ export class RichText extends Component { } } - willTrimSpaces( html ) { - const { tagName } = this.props; - - // aztec won't trim spaces in a case of
 block, so we are excluding it
-		if ( tagName === 'pre' ) {
-			return false;
-		}
-
-		// regex for detecting spaces around block element html tags
-		const blockHtmlElements =
-			'(div|br|blockquote|ul|ol|li|p|pre|h1|h2|h3|h4|h5|h6|iframe|hr)';
-		const leadingOrTrailingSpaces = new RegExp(
-			`(\\s+)<\/?${ blockHtmlElements }>|<\/?${ blockHtmlElements }>(\\s+)`,
-			'g'
-		);
-		const matches = html.match( leadingOrTrailingSpaces );
-		if ( matches && matches.length > 0 ) {
-			return true;
-		}
-
-		return false;
-	}
-
 	getHtmlToRender( record, tagName ) {
 		// Save back to HTML from React tree
 		let value = this.valueToFormat( record );
@@ -722,17 +698,7 @@ export class RichText extends Component {
 
 			// On AztecAndroid, setting the caret to an out-of-bounds position will crash the editor so, let's check for some cases.
 			if ( ! this.isIOS ) {
-				// Aztec performs some html text cleanup while parsing it so, its internal representation gets out-of-sync with the
-				// representation of the format-lib on the RN side. We need to avoid trying to set the caret position because it may
-				// be outside the text bounds and crash Aztec, at least on Android.
-				if ( this.willTrimSpaces( html ) ) {
-					// the html will get trimmed by the cleaning up functions in Aztec and caret position will get out-of-sync.
-					// So, skip forcing it, let Aztec just do its best and just log the fact.
-					console.warn(
-						'RichText value will be trimmed for spaces! Avoiding setting the caret position manually.'
-					);
-					selection = null;
-				} else if (
+				if (
 					this.props.selectionStart > record.text.length ||
 					this.props.selectionEnd > record.text.length
 				) {
diff --git a/packages/rich-text/src/component/test/index.native.js b/packages/rich-text/src/component/test/index.native.js
deleted file mode 100644
index c78999c58e73ea..00000000000000
--- a/packages/rich-text/src/component/test/index.native.js
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Internal dependencies
- */
-import { RichText } from '../index';
-
-describe( 'RichText Native', () => {
-	let richText;
-
-	beforeEach( () => {
-		richText = new RichText( { multiline: false } );
-	} );
-
-	describe( 'willTrimSpaces', () => {
-		it( 'exists', () => {
-			expect( richText ).toHaveProperty( 'willTrimSpaces' );
-		} );
-
-		it( 'is a function', () => {
-			expect( richText.willTrimSpaces ).toBeInstanceOf( Function );
-		} );
-
-		it( 'reports false for styled text with no outer spaces', () => {
-			const html =
-				'

Hello Hello WorldWorld!

'; - expect( richText.willTrimSpaces( html ) ).toBe( false ); - } ); - - it( 'reports false for Preformatted block', () => { - const html = '
Hello World 


'; - richText.props.tagName = 'pre'; - expect( richText.willTrimSpaces( html ) ).toBe( false ); - } ); - } ); -} );