Browse Source

fix: search not jump to the specific block

Tienson Qin 4 years ago
parent
commit
7accf8adbc
2 changed files with 9 additions and 8 deletions
  1. 1 2
      src/main/frontend/components/search.cljs
  2. 8 6
      src/main/frontend/handler/route.cljs

+ 1 - 2
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"

+ 8 - 6
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!
   []