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

Block Editor: Fix block search for non-Latin characters #44652

Merged
merged 2 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ module.exports = {
'uniqWith',
'upperFirst',
'values',
'words',
'xor',
'zip',
],
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/block-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"@wordpress/url": "file:../url",
"@wordpress/warning": "file:../warning",
"@wordpress/wordcount": "file:../wordcount",
"change-case": "^4.1.2",
"classnames": "^2.3.1",
"colord": "^2.7.0",
"diff": "^4.0.2",
Expand Down
18 changes: 3 additions & 15 deletions packages/block-editor/src/components/inserter/search-items.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* External dependencies
*/
import { noCase } from 'change-case';
import removeAccents from 'remove-accents';
import { find } from 'lodash';
import { find, words } from 'lodash';

// Default search helpers.
const defaultGetName = ( item ) => item.name || '';
Expand Down Expand Up @@ -36,17 +35,6 @@ function normalizeSearchInput( input = '' ) {
return input;
}

/**
* Extracts words from an input string.
*
* @param {string} input The input string.
*
* @return {Array} Words, extracted from the input string.
*/
function extractWords( input = '' ) {
return noCase( input ).split( ' ' ).filter( Boolean );
}

/**
* Converts the search term into a list of normalized terms.
*
Expand All @@ -55,7 +43,7 @@ function extractWords( input = '' ) {
* @return {string[]} The normalized list of search terms.
*/
export const getNormalizedSearchTerms = ( input = '' ) => {
return extractWords( normalizeSearchInput( input ) );
return words( normalizeSearchInput( input ) );
};

const removeMatchingTerms = ( unmatchedTerms, unprocessedTerms ) => {
Expand Down Expand Up @@ -162,7 +150,7 @@ export function getItemSearchRank( item, searchTerm, config = {} ) {
category,
collection,
].join( ' ' );
const normalizedSearchTerms = extractWords( normalizedSearchInput );
const normalizedSearchTerms = words( normalizedSearchInput );
const unmatchedTerms = removeMatchingTerms(
normalizedSearchTerms,
terms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ describe( 'getNormalizedSearchTerms', () => {
getNormalizedSearchTerms( ' Média & Text Tag-Cloud > 123' )
).toEqual( [ 'media', 'text', 'tag', 'cloud', '123' ] );
} );

it( 'should support non-latin letters', () => {
expect( getNormalizedSearchTerms( 'მედია' ) ).toEqual( [ 'მედია' ] );
} );
Comment on lines +46 to +48
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

} );

describe( 'getItemSearchRank', () => {
Expand Down