Rename text cleaning function to "normalizeText"

This commit is contained in:
Ronan Amicel 2022-08-17 18:40:46 +02:00
parent 4003d2d7c6
commit cd16650e0e
5 changed files with 11 additions and 11 deletions

View File

@ -21,7 +21,7 @@ export interface ACItem {
// Returns a trimmed, lowercase version of a string, // Returns a trimmed, lowercase version of a string,
// from which accents and other diacritics have been removed, // from which accents and other diacritics have been removed,
// so that autocomplete is case- and accent-insensitive. // so that autocomplete is case- and accent-insensitive.
export function cleanText(text: string): string { export function normalizeText(text: string): string {
return deburr(text).trim().toLowerCase(); return deburr(text).trim().toLowerCase();
} }
@ -99,7 +99,7 @@ export class ACIndexImpl<Item extends ACItem> implements ACIndex<Item> {
// The main search function. SearchText will be cleaned (trimmed and lowercased) at the start. // 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. // Empty search text returns the first N items in the search universe.
public search(searchText: string): ACResults<Item> { public search(searchText: string): ACResults<Item> {
const cleanedSearchText = cleanText(searchText); const cleanedSearchText = normalizeText(searchText);
const searchWords = cleanedSearchText.split(wordSepRegexp).filter(w => w); const searchWords = cleanedSearchText.split(wordSepRegexp).filter(w => w);
// Maps item index in _allItems to its score. // Maps item index in _allItems to its score.

View File

@ -8,7 +8,7 @@
* *
* It is currently used for auto-complete in the ReferenceEditor and ReferenceListEditor widgets. * It is currently used for auto-complete in the ReferenceEditor and ReferenceListEditor widgets.
*/ */
import {ACIndex, ACIndexImpl, cleanText as clean} from 'app/client/lib/ACIndex'; import {ACIndex, ACIndexImpl, normalizeText} from 'app/client/lib/ACIndex';
import {ColumnCache} from 'app/client/models/ColumnCache'; import {ColumnCache} from 'app/client/models/ColumnCache';
import {UserError} from 'app/client/models/errors'; import {UserError} from 'app/client/models/errors';
import {TableData} from 'app/client/models/TableData'; import {TableData} from 'app/client/models/TableData';
@ -45,7 +45,7 @@ export class ColumnACIndexes {
const items: ICellItem[] = valColumn.map((val, i) => { const items: ICellItem[] = valColumn.map((val, i) => {
const rowId = rowIds[i]; const rowId = rowIds[i];
const text = formatter.formatAny(val); const text = formatter.formatAny(val);
const cleanText = clean(text); const cleanText = normalizeText(text);
return {rowId, text, cleanText}; return {rowId, text, cleanText};
}); });
items.sort(itemCompare); items.sort(itemCompare);

View File

@ -1,5 +1,5 @@
import {createGroup} from 'app/client/components/commands'; import {createGroup} from 'app/client/components/commands';
import {ACIndexImpl, ACItem, ACResults, buildHighlightedDom, cleanText as clean, HighlightFunc} from 'app/client/lib/ACIndex'; import {ACIndexImpl, ACItem, ACResults, buildHighlightedDom, normalizeText, HighlightFunc} from 'app/client/lib/ACIndex';
import {IAutocompleteOptions} from 'app/client/lib/autocomplete'; import {IAutocompleteOptions} from 'app/client/lib/autocomplete';
import {IToken, TokenField, tokenFieldStyles} from 'app/client/lib/TokenField'; import {IToken, TokenField, tokenFieldStyles} from 'app/client/lib/TokenField';
import {colors, testId} from 'app/client/ui2018/cssVars'; import {colors, testId} from 'app/client/ui2018/cssVars';
@ -16,7 +16,7 @@ import {choiceToken, cssChoiceACItem, cssChoiceToken} from 'app/client/widgets/C
import {icon} from 'app/client/ui2018/icons'; import {icon} from 'app/client/ui2018/icons';
export class ChoiceItem implements ACItem, IToken { export class ChoiceItem implements ACItem, IToken {
public cleanText: string = clean(this.label); public cleanText: string = normalizeText(this.label);
constructor( constructor(
public label: string, public label: string,
public isInvalid: boolean, // If set, this token is not one of the valid choices. public isInvalid: boolean, // If set, this token is not one of the valid choices.

View File

@ -1,4 +1,4 @@
import { ACResults, buildHighlightedDom, cleanText as clean, HighlightFunc } from 'app/client/lib/ACIndex'; import { ACResults, buildHighlightedDom, normalizeText, HighlightFunc } from 'app/client/lib/ACIndex';
import { Autocomplete } from 'app/client/lib/autocomplete'; import { Autocomplete } from 'app/client/lib/autocomplete';
import { ICellItem } from 'app/client/models/ColumnACIndexes'; import { ICellItem } from 'app/client/models/ColumnACIndexes';
import { reportError } from 'app/client/models/errors'; import { reportError } from 'app/client/models/errors';
@ -115,7 +115,7 @@ export class ReferenceEditor extends NTextEditor {
this._showAddNew = false; this._showAddNew = false;
if (!this._enableAddNew || !text) { return result; } if (!this._enableAddNew || !text) { return result; }
const cleanText = clean(text); const cleanText = normalizeText(text);
if (result.items.find((item) => item.cleanText === cleanText)) { if (result.items.find((item) => item.cleanText === cleanText)) {
return result; return result;
} }

View File

@ -1,5 +1,5 @@
import { createGroup } from 'app/client/components/commands'; import { createGroup } from 'app/client/components/commands';
import { ACItem, ACResults, cleanText as clean, HighlightFunc } from 'app/client/lib/ACIndex'; import { ACItem, ACResults, normalizeText, HighlightFunc } from 'app/client/lib/ACIndex';
import { IAutocompleteOptions } from 'app/client/lib/autocomplete'; import { IAutocompleteOptions } from 'app/client/lib/autocomplete';
import { IToken, TokenField, tokenFieldStyles } from 'app/client/lib/TokenField'; import { IToken, TokenField, tokenFieldStyles } from 'app/client/lib/TokenField';
import { reportError } from 'app/client/models/errors'; import { reportError } from 'app/client/models/errors';
@ -26,7 +26,7 @@ class ReferenceItem implements IToken, ACItem {
* similar to getItemText() from IAutocompleteOptions. * similar to getItemText() from IAutocompleteOptions.
*/ */
public label: string = typeof this.rowId === 'number' ? String(this.rowId) : this.text; public label: string = typeof this.rowId === 'number' ? String(this.rowId) : this.text;
public cleanText: string = clean(this.text); public cleanText: string = normalizeText(this.text);
constructor( constructor(
public text: string, public text: string,
@ -264,7 +264,7 @@ export class ReferenceListEditor extends NewBaseEditor {
this._showAddNew = false; this._showAddNew = false;
if (!this._enableAddNew || !text) { return result; } if (!this._enableAddNew || !text) { return result; }
const cleanText = clean(text); const cleanText = normalizeText(text);
if (result.items.find((item) => item.cleanText === cleanText)) { if (result.items.find((item) => item.cleanText === cleanText)) {
return result; return result;
} }