Skip to content

Build your personal knowledge base with Trilium Notes

fix(search): highlight uppercase Greek final sigma

Elian Doran644ee7d9aa4a
diff --git a/apps/client/src/services/highlight_matches.ts b/apps/client/src/services/highlight_matches.ts
index da528db32b..1d6d756a4e 100644
--- a/apps/client/src/services/highlight_matches.ts
+++ b/apps/client/src/services/highlight_matches.ts
@@ -156,9 +156,9 @@ function findOffsets(regExp: RegExp, text: string) {
}
/**
- * Strips the diacritics of `text` and lowercases it, one code point at a time. `starts[i]` and
- * `ends[i]` are the bounds in `text` of the code point that produced `text[i]` of the result; a
- * combining mark that folds away joins the code point before it.
+ * Strips the diacritics of `text` and lowercases it, one code point at a time, with the final
+ * sigma ς as σ. `starts[i]` and `ends[i]` are the bounds in `text` of the code point that produced
+ * `text[i]` of the result; a combining mark that folds away joins the code point before it.
*/
function fold(text: string) {
let folded = "";
@@ -168,7 +168,8 @@ function fold(text: string) {
for (const char of text) {
const end = index + char.length;
- const replacement = char.normalize("NFD").replace(/\p{Diacritic}/gu, "").toLowerCase();
+ const replacement = char.normalize("NFD").replace(/\p{Diacritic}/gu, "").toLowerCase()
+ .replace("ς", "σ");
if (replacement.length === 0 && ends.length > 0) {
ends[ends.length - 1] = end;
}
diff --git a/apps/client/src/widgets/react/hooks.spec.tsx b/apps/client/src/widgets/react/hooks.spec.tsx
index 18b285e6b9..d5611934fc 100644
--- a/apps/client/src/widgets/react/hooks.spec.tsx
+++ b/apps/client/src/widgets/react/hooks.spec.tsx
@@ -702,6 +702,11 @@ describe("useImperativeSearchHighlighlighting", () => {
expect(markedTexts(el)).toHaveLength(500);
});
+ it("matches a final sigma whatever the case of the text", () => {
+ const el = highlight(["ος"], "<p>ΛΟΓΟΣ λογος</p>");
+ expect(markedTexts(el)).toEqual(["ΟΣ", "ος"]);
+ });
+
it("wraps a CJK substring match inside a larger word", () => {
const el = highlight(["笔记"], "<p>我的笔记本</p>");
expect(markedTexts(el)).toEqual(["笔记"]);