(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:
Jarosław Sadziński
2022-08-26 08:05:05 +02:00
parent 2cb783ea7b
commit b6f5718ad0
3 changed files with 55 additions and 28 deletions

View File

@@ -281,9 +281,18 @@ describe('ACIndex', function() {
it('should highlight multi-byte unicode', function() {
const acIndex = new ACIndexImpl(['Lorem ipsum 𝌆 dolor sit ameͨ͆t.', "mañana", "Москва"].map(makeItem), 3);
const acResult: ACResults<TestACItem> = acIndex.search("mañ моск am");
let acResult: ACResults<TestACItem> = acIndex.search("mañ моск am");
assert.deepEqual(acResult.items.map(i => acResult.highlightFunc(i.text)),
[["", "Моск", "ва"], ["", "mañ", "ana"], ["Lorem ipsum 𝌆 dolor sit ", "am", "eͨ͆t."]]);
const original = "ameͨ͆";
assert.equal(original.length, 5);
for (let end = 3; end <= original.length; end++) {
const text = original.slice(0, end); // i.e. test: ame, ameͨ, ameͨ͆ (hard to see the difference in some editors)
acResult = acIndex.search(text);
assert.deepEqual(acResult.items.map(i => acResult.highlightFunc(i.text))[0],
["Lorem ipsum 𝌆 dolor sit ", original, "t."]);
}
});
it('should match a brute-force scoring implementation', function() {