mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
Ignore diacritics in autocomplete
Works for: - Choice - Choice List - Reference - Reference List Co-Authored-By: Louis Delbosc <louis.delbosc.prestataire@anct.gouv.fr>
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* "lush" would only match the "L" in "Lavender".
|
||||
*/
|
||||
|
||||
import {localeCompare, nativeCompare, sortedIndex} from 'app/common/gutil';
|
||||
import {localeCompare, nativeCompare, removeDiacritics, sortedIndex} from 'app/common/gutil';
|
||||
import {DomContents} from 'grainjs';
|
||||
import escapeRegExp = require("lodash/escapeRegExp");
|
||||
|
||||
@@ -17,6 +17,12 @@ export interface ACItem {
|
||||
cleanText: string;
|
||||
}
|
||||
|
||||
// Returns a normalized, trimmed, lowercase version of a string, so that autocomplete is case-
|
||||
// and accent-insensitive.
|
||||
export function cleanText(text: string): string {
|
||||
return removeDiacritics(text).trim().toLowerCase();
|
||||
}
|
||||
|
||||
// Regexp used to split text into words; includes nearly all punctuation. This means that
|
||||
// "foo-bar" may be searched by "bar", but it's impossible to search for punctuation itself (e.g.
|
||||
// "a-b" and "a+b" are not distinguished). (It's easy to exclude unicode punctuation too if the
|
||||
@@ -91,7 +97,7 @@ export class ACIndexImpl<Item extends ACItem> implements ACIndex<Item> {
|
||||
// The main search function. SearchText will be cleaned (trimmed and lowercased) at the start.
|
||||
// Empty search text returns the first N items in the search universe.
|
||||
public search(searchText: string): ACResults<Item> {
|
||||
const cleanedSearchText = searchText.trim().toLowerCase();
|
||||
const cleanedSearchText = cleanText(searchText);
|
||||
const searchWords = cleanedSearchText.split(wordSepRegexp).filter(w => w);
|
||||
|
||||
// Maps item index in _allItems to its score.
|
||||
|
||||
Reference in New Issue
Block a user