Skip to content

Commit 2957b30

Browse files
committed
OpenConceptLab/ocl_issues#2299 | updated highlighter for synonym
1 parent b56a8aa commit 2957b30

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

src/components/map-projects/Concept.jsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import MapButton from './MapButton'
1313
import ConceptSummaryProperties from '../concepts/ConceptSummaryProperties'
1414

1515

16-
const getBestSynonym = synonyms => {
16+
const getBestSynonym = (synonyms = []) => {
1717
return synonyms
1818
.map(text => {
1919
const matches = [...text.matchAll(/<em>(.*?)<\/em>/g)];
@@ -23,23 +23,17 @@ const getBestSynonym = synonyms => {
2323
);
2424

2525
const emTag = `<em>${longestMatch}</em>`;
26-
const startsWithMatch = text.indexOf(emTag) === 0;
27-
28-
// prefer exact "<em>...</em>"
29-
const isExactEmOnly = text.trim() === emTag;
30-
3126
return {
3227
text,
33-
longestMatch,
3428
length: longestMatch.length,
35-
startsWithMatch,
36-
isExactEmOnly
29+
isExact: text.trim() === emTag,
30+
startsWith: text.startsWith(emTag)
3731
};
3832
})
3933
.sort((a, b) => {
40-
if (b.length !== a.length) return b.length - a.length; // longest match first
41-
if (b.isExactEmOnly !== a.isExactEmOnly) return b.isExactEmOnly ? 1 : -1; // ✅ exact "<em>...</em>" wins
42-
if (b.startsWithMatch !== a.startsWithMatch) return b.startsWithMatch ? 1 : -1; // prefer start
34+
if (b.isExact !== a.isExact) return b.isExact ? 1 : -1; // ✅ exact ALWAYS first
35+
if (b.length !== a.length) return b.length - a.length; // longer match
36+
if (b.startsWith !== a.startsWith) return b.startsWith ? 1 : -1;
4337
return 0;
4438
})[0]?.text;
4539
};

0 commit comments

Comments
 (0)