-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Adds support for matching blocks with diacritics using lodash.deburr #8707
Conversation
/cc @adamsilverstein Would love to get your feedback on this. |
term = term.toLowerCase(); | ||
term = term.trim(); | ||
|
||
return term; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Note: The test suite failure is failing on a strange e2e error. The tests work fine locally.
|
@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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
I've pushed af48c05 to your branch to resolve my latest feedback regarding documentation style. |
Thanks for the improvement! |
Description
Fixes #6387.
This PR updates the Gutenberg Block Inserter Menu to allow searching for terms that contain diacritics.
How has this been tested?
Types of changes
New feature
Checklist: