Tienson Qin 7 месяцев назад
Родитель
Сommit
dc8f2f4984

+ 5 - 1
deps/db/src/logseq/db/common/initial_data.cljs

@@ -201,7 +201,11 @@
 
 (defn ^:large-vars/cleanup-todo get-block-and-children
   [db id-or-page-name {:keys [children? children-only? nested-children? properties children-props]}]
-  (let [block (let [eid (cond (uuid? id-or-page-name) [:block/uuid id-or-page-name] (integer? id-or-page-name) id-or-page-name :else nil)]
+  (let [block (let [eid (cond (uuid? id-or-page-name)
+                              [:block/uuid id-or-page-name]
+                              (integer? id-or-page-name)
+                              id-or-page-name
+                              :else nil)]
                 (cond
                   eid
                   (d/entity db eid)

+ 8 - 5
src/main/frontend/components/block.cljs

@@ -611,11 +611,14 @@
 
 (declare page-reference)
 
-(defn open-page-ref
+(defn <open-page-ref
   [config page-entity e page-name contents-page?]
   (when (not (util/right-click? e))
-    (let [ignore-alias? (:ignore-alias? config)
-          page (or (and (not ignore-alias?) (first (:block/_alias page-entity))) page-entity)]
+    (p/let [ignore-alias? (:ignore-alias? config)
+            page (or (and (not ignore-alias?)
+                          (or (first (:block/_alias page-entity))
+                              (db-async/<get-block-source (state/get-current-repo) (:db/id page-entity))))
+                     page-entity)]
       (cond
         (gobj/get e "shiftKey")
         (when page
@@ -708,12 +711,12 @@
                           (util/stop e)
                           (state/clear-edit!)
                           (when-not (:disable-click? config)
-                            (open-page-ref config page-entity e page-name contents-page?))
+                            (<open-page-ref config page-entity e page-name contents-page?))
                           (reset! *mouse-down? false)))
        :on-key-up (fn [e] (when (and e (= (.-key e) "Enter") (not other-position?))
                             (util/stop e)
                             (state/clear-edit!)
-                            (open-page-ref config page-entity e page-name contents-page?)))}
+                            (<open-page-ref config page-entity e page-name contents-page?)))}
        on-context-menu
        (assoc :on-context-menu on-context-menu))
      (when (and show-icon? (not tag?))

+ 9 - 6
src/main/frontend/components/cmdk/core.cljs

@@ -281,15 +281,16 @@
 (defn- page-item
   [repo page]
   (let [entity (db/entity [:block/uuid (:block/uuid page)])
-        source-page (or (:block/title (model/get-alias-source-page repo (:db/id entity)))
+        source-page (or (model/get-alias-source-page repo (:db/id entity))
                         (:alias page))
         icon (get-page-icon entity)
         title (block-handler/block-unique-title page)
-        title' (if source-page (str title " -> alias: " source-page) title)]
+        title' (if source-page (str title " -> alias: " (:block/title source-page)) title)]
     (hash-map :icon icon
               :icon-theme :gray
               :text title'
-              :source-page (or source-page page))))
+              :source-page (or source-page page)
+              :alias (:alias page))))
 
 (defn- block-item
   [repo block current-page !input]
@@ -437,9 +438,11 @@
 
 (defn- get-highlighted-page-uuid-or-name
   [state]
-  (let [highlighted-item (some-> state state->highlighted-item)]
-    (or (:block/uuid (:source-block highlighted-item))
-        (:block/uuid (:source-page highlighted-item)))))
+  (let [highlighted-item (some-> state state->highlighted-item)
+        block (or (:alias highlighted-item)
+                  (:source-block highlighted-item)
+                  (:source-page highlighted-item))]
+    (:block/uuid block)))
 
 (defmethod handle-action :open-page [_ state _event]
   (when-let [page-name (get-highlighted-page-uuid-or-name state)]

+ 1 - 1
src/main/frontend/components/editor.cljs

@@ -223,7 +223,7 @@
                                  :else
                                  (ui/icon "letter-n" {:size 14}))])
 
-                            (let [title (let [alias (:alias block')
+                            (let [title (let [alias (get-in block' [:alias :block/title])
                                               title (if (and db-based? (not (ldb/built-in? block')))
                                                       (block-handler/block-unique-title block')
                                                       (:block/title block'))]

+ 7 - 0
src/main/frontend/db/async.cljs

@@ -151,6 +151,13 @@
             _ (d/transact! conn result)]
       result)))
 
+(defn <get-block-source
+  [graph id]
+  (assert (integer? id))
+  (p/let [source-id (state/<invoke-db-worker :thread-api/get-block-source graph id)]
+    (when source-id
+      (<get-block graph source-id {:children? false}))))
+
 (defn <get-block-refs
   [graph eid]
   (assert (integer? eid))

+ 5 - 0
src/main/frontend/worker/db_worker.cljs

@@ -469,6 +469,11 @@
   (when-let [conn (worker-state/get-datascript-conn repo)]
     (ldb/get-block-refs-count @conn id)))
 
+(def-thread-api :thread-api/get-block-source
+  [repo id]
+  (when-let [conn (worker-state/get-datascript-conn repo)]
+    (:db/id (first (:block/_alias (d/entity @conn id))))))
+
 (def-thread-api :thread-api/block-refs-check
   [repo id {:keys [unlinked?]}]
   (when-let [conn (worker-state/get-datascript-conn repo)]

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

@@ -326,7 +326,8 @@ DROP TRIGGER IF EXISTS blocks_au;
                                                    nil)
                                      :block/tags (seq (map :db/id (:block/tags block)))
                                      :page? (ldb/page? block)
-                                     :alias (:block/title (first (:block/_alias block)))}))))))
+                                     :alias (some-> (first (:block/_alias block))
+                                                    (select-keys [:block/uuid :block/title]))}))))))
           page-or-object-result (filter (fn [b] (or (:page? b) (:block/tags result))) result)]
       (->>
        (concat page-or-object-result