From 56bd8dd47c666cfaa04f43f11a0f0a49ca99a3a6 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 15 Aug 2023 21:11:05 +0800 Subject: [PATCH] fix: add block below linked block --- src/main/frontend/modules/outliner/core.cljs | 31 ++++++++++++-------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/frontend/modules/outliner/core.cljs b/src/main/frontend/modules/outliner/core.cljs index d03ac59747..9fa2af2ce9 100644 --- a/src/main/frontend/modules/outliner/core.cljs +++ b/src/main/frontend/modules/outliner/core.cljs @@ -616,17 +616,23 @@ blocks))) (defn- get-target-block - [target-block sibling?] + [target-block sibling? outliner-op] (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?]))) + (let [linked (:block/link block)] + (cond + (contains? #{:insert-blocks} outliner-op) + [block sibling?] + + linked + (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)]) + :else + [block sibling?])))) (defn insert-blocks "Insert blocks as children (or siblings) of target-node. @@ -645,7 +651,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' sibling?] (get-target-block target-block sibling?) + (let [[target-block' sibling?] (get-target-block target-block sibling? outliner-op) _ (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) @@ -829,7 +835,7 @@ [blocks target-block {:keys [sibling? outliner-op]}] [:pre [(seq blocks) (s/valid? ::block-map-or-entity target-block)]] - (let [[target-block sibling?] (get-target-block target-block sibling?) + (let [[target-block sibling?] (get-target-block target-block sibling? outliner-op) _ (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?)] @@ -996,7 +1002,7 @@ (defn insert-blocks! [blocks target-block opts] - (let [r (op-transact! #'insert-blocks blocks target-block opts) + (let [r (op-transact! #'insert-blocks blocks target-block (assoc opts :outliner-op :insert-blocks)) repo (:repo *transaction-args*) persist-op? (:persist-op? *transaction-args*)] (when (and persist-op? repo) @@ -1009,7 +1015,7 @@ persist-op? (:persist-op? *transaction-args*)] (when (and persist-op? repo) (rtc-op/