|
|
@@ -32,44 +32,48 @@
|
|
|
(when-not (string/blank? highlighted-text) [:span {:class "bg-accent-06 dark:bg-accent-08-alpha"} highlighted-text])
|
|
|
(when-not (string/blank? after-text) [:span after-text])]))
|
|
|
|
|
|
-(defn span-with-mutliple-highlight-tokens [app-config text query normal-text normal-query]
|
|
|
- (loop [[query-token & more] (string/split normal-query #" ")
|
|
|
- result [[:text (to-string text)]]]
|
|
|
- (if-not query-token
|
|
|
- (->> result
|
|
|
- (map (fn [[type value]]
|
|
|
- (if (= type :text)
|
|
|
- [:span value]
|
|
|
- [:span {:style {:background "var(--lx-accent-09)"}} value])))
|
|
|
- (into [:span]))
|
|
|
- (->> result
|
|
|
- (mapcat (fn [[type value]]
|
|
|
- (if-not (and (= type :text) (string? value) (string/includes? value query-token))
|
|
|
- [[type value]]
|
|
|
- (let [normal-value (normalize-text app-config value)
|
|
|
- normal-query-token (normalize-text app-config query-token)
|
|
|
- [before-text highlighted-text after-text] (split-text-on-highlight value query-token normal-value normal-query-token)]
|
|
|
- [[:text before-text]
|
|
|
- [:match highlighted-text]
|
|
|
- [:text after-text]]))))
|
|
|
- (recur more)))))
|
|
|
+(defn span-with-multiple-highlight-tokens [app-config text normal-query]
|
|
|
+ (let [normalized-text (normalize-text app-config text)]
|
|
|
+ (loop [[query-token & more] (string/split normal-query #" ")
|
|
|
+ result [[:text (to-string text)]]]
|
|
|
+ (if-not query-token
|
|
|
+ (->> result
|
|
|
+ (map (fn [[type value]]
|
|
|
+ (if (= type :text)
|
|
|
+ [:span value]
|
|
|
+ [:span {:style {:background "var(--lx-accent-09)"}} value])))
|
|
|
+ (into [:span]))
|
|
|
+ (->> result
|
|
|
+ (mapcat (fn [[type value]]
|
|
|
+ (let [include-token? (and (= type :text) (string? value)
|
|
|
+ (string/includes? normalized-text query-token))]
|
|
|
+ (if include-token?
|
|
|
+ (let [normal-value (normalize-text app-config value)
|
|
|
+ normal-query-token (normalize-text app-config query-token)
|
|
|
+ [before-text highlighted-text after-text] (split-text-on-highlight value query-token normal-value normal-query-token)]
|
|
|
+ [[:text before-text]
|
|
|
+ [:match highlighted-text]
|
|
|
+ [:text after-text]])
|
|
|
+ [[type value]]))))
|
|
|
+ (recur more))))))
|
|
|
|
|
|
(defn highlight-query* [app-config query text]
|
|
|
(if (vector? text) ; hiccup
|
|
|
text
|
|
|
(let [text-string (to-string text)]
|
|
|
- (if-not (seq text-string) [:span text-string]
|
|
|
- (let [normal-text (normalize-text app-config text-string)
|
|
|
- normal-query (normalize-text app-config query)]
|
|
|
- (cond
|
|
|
- (and (string? query) (re-find #" " query))
|
|
|
- (span-with-mutliple-highlight-tokens app-config text-string query normal-text normal-query)
|
|
|
+ (if-not (seq text-string)
|
|
|
+ [:span text-string]
|
|
|
+ (let [normal-text (normalize-text app-config text-string)
|
|
|
+ normal-query (normalize-text app-config query)]
|
|
|
+ (cond
|
|
|
+ (and (string? query) (re-find #" " query))
|
|
|
+ (span-with-multiple-highlight-tokens app-config text-string normal-query)
|
|
|
;; When the match is present and only a single token, highlight that token
|
|
|
- (string/includes? normal-text normal-query)
|
|
|
- (span-with-single-highlight-token text-string query normal-text normal-query)
|
|
|
+ (string/includes? normal-text normal-query)
|
|
|
+ (span-with-single-highlight-token text-string query normal-text normal-query)
|
|
|
;; Otherwise, just return the text
|
|
|
- :else
|
|
|
- [:span text-string]))))))
|
|
|
+ :else
|
|
|
+ [:span text-string]))))))
|
|
|
|
|
|
(rum/defc root [{:keys [icon icon-theme query text info shortcut value-label value
|
|
|
title highlighted on-highlight on-highlight-dep header on-click
|