Browse Source

fix: `t o` to toggle open all blocks

related to https://github.com/logseq/db-test/issues/423
Tienson Qin 4 months ago
parent
commit
be2977dd40

+ 9 - 2
deps/db/src/logseq/db/common/initial_data.cljs

@@ -216,7 +216,8 @@
                   nil))
         block-refs-count? (some #{:block.temp/refs-count} properties)]
     (when block
-      ;; (prn :debug :get-block (:db/id block) (:block/title block) :children? children?)
+      (prn :debug :get-block (:db/id block) (:block/title block) :children? children?
+           :include-collapsed-children? include-collapsed-children?)
       (let [children (when children?
                        (let [children-blocks (get-block-children db (:block/uuid block) {:include-collapsed-children? include-collapsed-children?})
                              large-page? (>= (count children-blocks) 100)
@@ -243,7 +244,13 @@
                      block-refs-count?
                      (assoc :block.temp/refs-count (get-block-refs-count db (:db/id block)))
                      true
-                     (assoc :block.temp/load-status (if (and children? (empty? properties)) :full :self)))]
+                     (assoc :block.temp/load-status (cond
+                                                      (and children? include-collapsed-children? (empty? properties))
+                                                      :full
+                                                      (and children? (empty? properties))
+                                                      :children
+                                                      :else
+                                                      :self)))]
         (cond->
          {:block block'}
           children?

+ 13 - 8
src/main/frontend/db/async.cljs

@@ -80,7 +80,7 @@
                              (assoc opts :property-ident property-id))))
 
 (defn <get-block
-  [graph id-uuid-or-name & {:keys [children? skip-transact? skip-refresh? children-only? properties]
+  [graph id-uuid-or-name & {:keys [children? include-collapsed-children? skip-transact? skip-refresh? properties]
                             :or {children? true}
                             :as opts}]
 
@@ -101,7 +101,8 @@
         load-status (:block.temp/load-status e)]
     (cond
       (and (or (= load-status :full)
-               (and (= load-status :self) (not children?) (not children-only?)))
+               (and (= load-status :children) (not include-collapsed-children?))
+               (and (= load-status :self) (not children?)))
            (not (some #{:block.temp/refs-count} properties)))
       (p/promise e)
 
@@ -114,16 +115,20 @@
            (let [conn (db/get-db graph false)
                  block-and-children (if block (cons block children) children)
                  affected-keys [[:frontend.worker.react/block (:db/id block)]]
-                 tx-data (->> (remove (fn [b] (:block.temp/load-status (db/entity (:db/id b)))) block-and-children)
-                              (common-util/fast-remove-nils)
-                              (remove empty?))]
+                 tx-data (concat
+                          (->> (remove (fn [b] (:block.temp/load-status (db/entity (:db/id b))))
+                                       block-and-children)
+                               (common-util/fast-remove-nils)
+                               (remove empty?))
+                          (when (and (:db/id block) children? include-collapsed-children?
+                                     (not= :full (:block.temp/load-status (some-> (:db/id block) db/entity))))
+                            [{:db/id (:db/id block)
+                              :block.temp/load-status :full}]))]
              (when (seq tx-data) (d/transact! conn tx-data))
              (when-not skip-refresh?
                (react/refresh-affected-queries! graph affected-keys {:skip-kv-custom-keys? true}))))
 
-         (if children-only?
-           children
-           (if skip-transact? block (db/entity (:db/id block)))))
+         (if skip-transact? block (db/entity (:db/id block))))
        (p/catch (fn [error]
                   (js/console.error error)
                   (throw (ex-info "get-block error" {:block id-uuid-or-name}))))))))

+ 12 - 11
src/main/frontend/handler/editor.cljs

@@ -3504,12 +3504,18 @@
                       (state/get-current-page)
                       (date/today))]
     (p/let [block-id (or root-block (parse-uuid page))
-            page-id (when-not block-id
-                      (:db/id (db/get-page page)))
+            page-id (let [page-entity (db/get-page page)]
+                      (if (config/db-based-graph?)
+                        (when (ldb/page? page-entity)
+                          (:block/uuid page-entity))
+                        (when-not block-id
+                          (:block/uuid page-entity))))
             repo (state/get-current-repo)
-            result (db-async/<get-block repo (or block-id page-id)
-                                        {:children-only? true
-                                         :include-collapsed-children? true})
+            _ (db-async/<get-block repo (or block-id page-id)
+                                   {:children? true
+                                    :include-collapsed-children? true})
+            entity (db/entity [:block/uuid (or block-id page-id)])
+            result (or (:block/_page entity) (:block/_parent entity))
             blocks (if page-id
                      result
                      (cons (db/entity [:block/uuid block-id]) result))
@@ -3585,7 +3591,7 @@
 (defn expand-block! [block-id & {:keys [skip-db-collpsing?]}]
   (let [repo (state/get-current-repo)]
     (p/do!
-     (db-async/<get-block repo block-id {:children-only? true
+     (db-async/<get-block repo block-id {:children? true
                                          :include-collapsed-children? true})
      (when-not (or skip-db-collpsing? (skip-collapsing-in-db?))
        (set-blocks-collapsed! [block-id] false))
@@ -3694,11 +3700,6 @@
                (doseq [block-id block-ids] (collapse-block! block-id))))))
        (and clear-selection? (clear-selection!)))
 
-     (whiteboard?)
-      ;; TODO: Looks like detecting the whiteboard selection's collapse state will take more work.
-      ;; Leaving unimplemented for now.
-     nil
-
      :else
       ;; If no block is being edited or selected, the "toggle" action doesn't make sense,
       ;; so we no-op here, unlike in the expand! & collapse! functions.