Parcourir la source

fix: current page search

Tienson Qin il y a 2 ans
Parent
commit
c13565b90a

+ 8 - 8
src/main/frontend/components/cmdk.cljs

@@ -229,21 +229,21 @@
   (let [!input (::input state)
         !results (::results state)
         repo (state/get-current-repo)
-        current-page (page-util/get-current-page-id)
+        current-page (when-let [id (page-util/get-current-page-id)]
+                       (db/entity id))
         opts {:limit 100}]
     (swap! !results assoc-in [group :status] :loading)
     (swap! !results assoc-in [:current-page :status] :loading)
     (p/let [blocks (search/block-search repo @!input opts)
             blocks (remove nil? blocks)
             items (map (fn [block]
-                         (let [id (if (uuid? (:block/uuid block))
-                                    (:block/uuid block)
-                                    (uuid (:block/uuid block)))]
+                         (let [id (:block/uuid block)]
                            {:icon "block"
                             :icon-theme :gray
                             :text (:block/content block)
                             :header (block/breadcrumb {:search? true} repo id {})
-                            :current-page? (some-> block :block/page #{current-page})
+                            :current-page? (when-let [page-id (:block/page block)]
+                                             (= page-id (:block/uuid current-page)))
                             :source-block block})) blocks)
             items-on-other-pages (remove :current-page? items)
             items-on-current-page (filter :current-page? items)]
@@ -314,7 +314,7 @@
       (load-results :files state))))
 
 (defn- copy-block-ref [state]
-  (when-let [block-uuid (some-> state state->highlighted-item :source-block :block/uuid uuid)]
+  (when-let [block-uuid (some-> state state->highlighted-item :source-block :block/uuid)]
     (editor-handler/copy-block-ref! block-uuid block-ref/->block-ref)
     (state/close-modal!)))
 
@@ -331,7 +331,7 @@
     (state/close-modal!)))
 
 (defmethod handle-action :open-block [_ state _event]
-  (let [block-id (some-> state state->highlighted-item :source-block :block/uuid uuid)
+  (let [block-id (some-> state state->highlighted-item :source-block :block/uuid)
         get-block-page (partial model/get-block-page (state/get-current-repo))]
     (when-let [page (some-> block-id get-block-page)]
       (let [page-name (:block/name page)]
@@ -349,7 +349,7 @@
     (state/close-modal!)))
 
 (defmethod handle-action :open-block-right [_ state _event]
-  (when-let [block-uuid (some-> state state->highlighted-item :source-block :block/uuid uuid)]
+  (when-let [block-uuid (some-> state state->highlighted-item :source-block :block/uuid)]
     (editor-handler/open-block-in-sidebar! block-uuid)
     (state/close-modal!)))
 

+ 1 - 2
src/main/frontend/search.cljs

@@ -93,8 +93,7 @@
 (defn block-search
   [repo q option]
   (when-let [engine (get-engine repo)]
-    (let [q (util/search-normalize q (state/enable-search-remove-accents?))
-          q (if (util/electron?) q (escape-str q))]
+    (let [q (util/search-normalize q (state/enable-search-remove-accents?))]
       (when-not (string/blank? q)
         (protocol/query engine q option)))))
 

+ 4 - 5
src/main/frontend/search/browser.cljs

@@ -15,11 +15,10 @@
     (if-let [^js sqlite @*sqlite]
       (p/let [result (.search-blocks sqlite (state/get-current-repo) q (bean/->js option))
               result (bean/->clj result)]
-        (keep (fn [{:keys [content uuid page]}]
-                (when-not (> (count content) (state/block-content-max-length repo))
-                  {:block/uuid uuid
-                   :block/content content
-                   :block/page page})) result))
+        (keep (fn [{:keys [content page] :as block}]
+                {:block/uuid (uuid (:uuid block))
+                 :block/content content
+                 :block/page (uuid page)}) result))
       (p/resolved nil)))
   (rebuild-blocks-indice! [this]
     (if-let [^js sqlite @*sqlite]