Skip to content

Commit

Permalink
fix(search): rm lowercase normalization for query terms
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Feb 29, 2024
1 parent 27433ed commit ae41c6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions deps/shui/src/logseq/shui/list_item/v1.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@

(def to-string shortcut/to-string)

(defn normalize-text [app-config text]
(defn- normalize-text [app-config text]
(cond-> (to-string text)
:lower-case (string/lower-case)
;; :lower-case (string/lower-case)
:normalize (.normalize "NFKC")
(:feature/enable-search-remove-accents? app-config) (remove-accents)))

(defn highlight-query* [app-config query text]
(if (vector? text) ; hiccup
(cond
(vector? text) ; hiccup
text

(string/blank? query)
[:span (to-string text)]

:else
(when-let [text-string (not-empty (to-string text))]
(let [normal-text (normalize-text app-config text-string)
normal-query (normalize-text app-config query)
query-terms (string/replace (gstring/regExpEscape normal-query) #"\s+" "|")
query-re (re-pattern (str "(" query-terms ")"))
query-re (js/RegExp. (str "(" query-terms ")") "i")
highlighted-text (string/replace normal-text query-re "<:hlmarker>$1<:hlmarker>")
segs (string/split highlighted-text #"<:hlmarker>")]
(if (seq segs)
Expand All @@ -32,7 +38,7 @@
[:span seg]
[:span {:class "ui__list-item-highlighted-span"} seg]))
segs))
[:span text-string])))))
[:span normal-text])))))

(rum/defc root [{:keys [icon icon-theme query text info shortcut value-label value
title highlighted on-highlight on-highlight-dep header on-click
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/page-search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function alias_test(block: Block, page: Page, page_name: string, search_kw
const results = await searchPage(page, kw_name)

// test search results
expect(await results[0].innerText()).toContain(alias_name)
expect(await results[0].innerText()).toContain(alias_name.normalize('NFKC'))

// test search entering (page)
page.keyboard.press("Enter")
Expand Down

0 comments on commit ae41c6d

Please sign in to comment.