Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for matching blocks with diacritics using lodash.deburr #8707

Merged

Conversation

dsawardekar
Copy link
Contributor

Description

Fixes #6387.

This PR updates the Gutenberg Block Inserter Menu to allow searching for terms that contain diacritics.

How has this been tested?

  • I added unit tests for the normalizeTerm function and run the test suite successfully.
  • I created a new sample block called 'Example Média Block'. And was able to match on this block in the inserter after my change.

Types of changes

New feature

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.standards
  • My code has proper inline documentation.

@dsawardekar
Copy link
Contributor Author

/cc @adamsilverstein Would love to get your feedback on this.

term = term.toLowerCase();
term = term.trim();

return term;
Copy link
Contributor

@paulwilde paulwilde Aug 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this just be simplified to return deburr( term ).toLowerCase().trim(); and still be as readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it could be. I've left it separate to allow for additional normalizations. I suspect there will be a few more like #8466.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally fine with this. If we want to get fancy-functional, we could also use Lodash's _.flow to compose them:

export const normalizeTerm = flow( [
	deburr,
	lowerCase,
	trim,
] );


return items.filter( ( item ) =>
matchSearch( item.title ) || some( item.keywords, matchSearch )
);
};

/**
* Converts the search term into a normalized term, removing diacritics
* and whitespace.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clearer, is it only removing leading and trailing whitespace, or all whitespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @aduth I've updated the comment message to add clarity.

@dsawardekar
Copy link
Contributor Author

Note: The test suite failure is failing on a strange e2e error. The tests work fine locally.

    - Snapshot
    + Received
      "<!-- wp:paragraph -->
    - <p><strong></strong></p>
    + <p></p>
      <!-- /wp:paragraph -->"
      147 | 		await clickBlockAppender();
      148 | 		await pressWithModifier( 'mod', 'b' );
    > 149 | 		expect( await getEditedPostContent() ).toMatchSnapshot();
          | 		                                       ^
      150 | 
      151 | 		// When returning to Visual mode, backspace in selected block should
      152 | 		// reset to an unmodified default block.

@aduth
Copy link
Member

aduth commented Aug 13, 2018

@dsawardekar Our end-to-end tests have been less-than-reliable as of late. I've restarted the build on Travis. See also #6956.

term = term.toLowerCase();
term = term.trim();

return term;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally fine with this. If we want to get fancy-functional, we could also use Lodash's _.flow to compose them:

export const normalizeTerm = flow( [
	deburr,
	lowerCase,
	trim,
] );

* lowercase.
*
* @param {string} term The search term to normalize
* @return {string} The normalized search term
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conventionally we're including a newline before the @return JSDoc tag, per documentation example at:

https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/javascript/#functions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also periods after each sentence.

Period after sentence. Newline before return statement. 80 column line-width.
@aduth
Copy link
Member

aduth commented Aug 13, 2018

I've pushed af48c05 to your branch to resolve my latest feedback regarding documentation style.

@aduth aduth merged commit 0595c3e into WordPress:master Aug 13, 2018
@mtias mtias added this to the 3.6 milestone Aug 16, 2018
@mtias mtias added the [Feature] Inserter The main way to insert blocks using the + button in the editing interface label Aug 16, 2018
@mtias
Copy link
Member

mtias commented Aug 16, 2018

Thanks for the improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants