mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Fixing ACIndex highlightMatches functions
Summary: Highlighting wasn't working correctly for the new normalized search for autocomplate widgets. Test Plan: Existing tests Reviewers: alexmojaki Reviewed By: alexmojaki Differential Revision: https://phab.getgrist.com/D3602
This commit is contained in:
@@ -11,6 +11,7 @@ import {localeCompare, nativeCompare, sortedIndex} from 'app/common/gutil';
|
||||
import {DomContents} from 'grainjs';
|
||||
import escapeRegExp = require("lodash/escapeRegExp");
|
||||
import deburr = require("lodash/deburr");
|
||||
import split = require("lodash/split");
|
||||
|
||||
export interface ACItem {
|
||||
// This should be a trimmed lowercase version of the item's text. It may be an accessor.
|
||||
@@ -243,11 +244,17 @@ function highlightMatches(searchWords: string[], text: string): string[] {
|
||||
for (let i = 0; i < textParts.length; i += 2) {
|
||||
const word = textParts[i];
|
||||
const separator = textParts[i + 1] || '';
|
||||
const prefixLen = findLongestPrefixLen(word.toLowerCase(), searchWords);
|
||||
// deburr (remove diacritics) was used to produce searchWords, so `word` needs to match that.
|
||||
const prefixLen = findLongestPrefixLen(deburr(word).toLowerCase(), searchWords);
|
||||
if (prefixLen === 0) {
|
||||
outputs[outputs.length - 1] += word + separator;
|
||||
} else {
|
||||
outputs.push(word.slice(0, prefixLen), word.slice(prefixLen) + separator);
|
||||
// Split into unicode 'characters' that keep diacritics combined
|
||||
const chars = split(word, '');
|
||||
outputs.push(
|
||||
chars.slice(0, prefixLen).join(''),
|
||||
chars.slice(prefixLen).join('') + separator
|
||||
);
|
||||
}
|
||||
}
|
||||
return outputs;
|
||||
|
||||
Reference in New Issue
Block a user