From 7accf8adbca6b60777c8d3df35a4fa5acc739375 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 25 Feb 2021 20:26:45 +0800 Subject: [PATCH] fix: search not jump to the specific block --- src/main/frontend/components/search.cljs | 3 +-- src/main/frontend/handler/route.cljs | 14 ++++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/frontend/components/search.cljs b/src/main/frontend/components/search.cljs index 1803a5ebb..e263b1895 100644 --- a/src/main/frontend/components/search.cljs +++ b/src/main/frontend/components/search.cljs @@ -256,7 +256,6 @@ :clip-rule "evenodd" :fill-rule "evenodd"}]]] [:input#search_field.block.w-full.h-full.pr-3.py-2.rounded-md.focus:outline-none.placeholder-gray-500.focus:placeholder-gray-400.sm:text-sm.sm:bg-transparent - {:style {:padding-left "2rem"} :placeholder (t :search) :auto-complete (if (util/chrome?) "chrome-off" "off") ; off not working here @@ -272,7 +271,7 @@ (reset! search-timeout (js/setTimeout #(search-handler/search value) - 100))))))}] + 200))))))}] (when-not (string/blank? search-q) (ui/css-transition {:class-names "fade" diff --git a/src/main/frontend/handler/route.cljs b/src/main/frontend/handler/route.cljs index 148fdacb9..6d7cd99ae 100644 --- a/src/main/frontend/handler/route.cljs +++ b/src/main/frontend/handler/route.cljs @@ -78,17 +78,19 @@ title (get-title (:name data) path-params)] (util/set-title! title))) +(defn jump-to-anchor! + [anchor-text] + (when anchor-text + (ui-handler/highlight-element! anchor-text))) + (defn set-route-match! [route] (let [route route] (swap! state/state assoc :route-match route) (update-page-title! route) - (util/scroll-to-top))) - -(defn jump-to-anchor! - [anchor-text] - (when anchor-text - (ui-handler/highlight-element! anchor-text))) + (when-let [anchor (get-in route [:query-params :anchor])] + (jump-to-anchor! anchor) + (util/scroll-to-top)))) (defn go-to-search! []