From 0b2bb80bb804e7f8b9b9b6956ee95f8e085fcda3 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 19 Feb 2024 10:01:54 +0000 Subject: [PATCH] Desktop: Fixes #9958: Highlight partial matches in search results --- packages/lib/markJsUtils.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/lib/markJsUtils.js b/packages/lib/markJsUtils.js index f2fc5113e..c09867df5 100644 --- a/packages/lib/markJsUtils.js +++ b/packages/lib/markJsUtils.js @@ -24,10 +24,17 @@ markJsUtils.markKeyword = (mark, keyword, stringUtils, extraOptions = null) => { const isBasicSearch = ['ja', 'zh', 'ko'].indexOf(keyword.scriptType) >= 0; let value = keyword.value; - let accuracy = keyword.accuracy ? keyword.accuracy : { value: 'exactly', limiters: ':;.,-–—‒_(){}[]!\'"+='.split('') }; - if (isBasicSearch) accuracy = 'partially'; + + const getAccuracy = (keyword) => { + if (isBasicSearch) return 'partially'; + if (keyword.type === 'regex') return 'complementary'; + if (keyword.accuracy) return keyword.accuracy; + return keyword.value.length >= 2 ? 'partially' : { value: 'exactly', limiters: ':;.,-–—‒_(){}[]!\'"+='.split('') }; + }; + + const accuracy = getAccuracy(keyword); + if (keyword.type === 'regex') { - accuracy = 'complementary'; // Remove the trailing wildcard and "accuracy = complementary" will take // care of highlighting the relevant keywords.