From ecfed114f58753fb9eb197cff9166854069b0981 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 15 Aug 2023 19:35:28 +0800 Subject: [PATCH] allow indent a block to a linked page --- src/main/frontend/modules/outliner/core.cljs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/frontend/modules/outliner/core.cljs b/src/main/frontend/modules/outliner/core.cljs index bfbeacfa99..e4fc7305fd 100644 --- a/src/main/frontend/modules/outliner/core.cljs +++ b/src/main/frontend/modules/outliner/core.cljs @@ -612,11 +612,17 @@ blocks))) (defn- get-target-block - [target-block] - (if (:db/id target-block) - (db/pull (:db/id target-block)) - (when (:block/uuid target-block) - (db/pull [:block/uuid (:block/uuid target-block)])))) + [target-block sibling?] + (when-let [block (if (:db/id target-block) + (db/entity (:db/id target-block)) + (when (:block/uuid target-block) + (db/entity [:block/uuid (:block/uuid target-block)])))] + (if-let [linked (:block/link block)] + (let [last-child (some-> (db-model/get-block-last-direct-child (conn/get-db) (:db/id linked)) + db/entity) + target (or last-child linked)] + [target (if last-child true false)]) + [block sibling?]))) (defn insert-blocks "Insert blocks as children (or siblings) of target-node. @@ -635,7 +641,7 @@ [blocks target-block {:keys [sibling? keep-uuid? outliner-op replace-empty-target?] :as opts}] {:pre [(seq blocks) (s/valid? ::block-map-or-entity target-block)]} - (let [target-block' (get-target-block target-block) + (let [[target-block' sibling?] (get-target-block target-block sibling?) _ (assert (some? target-block') (str "Invalid target: " target-block)) sibling? (if (page-block? target-block') false sibling?) move? (contains? #{:move-blocks :move-blocks-up-down :indent-outdent-blocks} outliner-op) @@ -819,7 +825,7 @@ [blocks target-block {:keys [sibling? outliner-op]}] [:pre [(seq blocks) (s/valid? ::block-map-or-entity target-block)]] - (let [target-block (get-target-block target-block) + (let [[target-block sibling?] (get-target-block target-block sibling?) _ (assert (some? target-block) (str "Invalid target: " target-block)) non-consecutive-blocks? (seq (db-model/get-non-consecutive-blocks blocks)) original-position? (move-to-original-position? blocks target-block sibling? non-consecutive-blocks?)]