From ef287afb70831d55e351b8e44539a1268a0cd0f7 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 29 Nov 2022 10:30:30 +0800 Subject: [PATCH] fix: can't paste in the first block if it's empty close #7500 --- src/main/frontend/modules/outliner/core.cljs | 27 +++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/frontend/modules/outliner/core.cljs b/src/main/frontend/modules/outliner/core.cljs index 3cf8030ca..31df65c3c 100644 --- a/src/main/frontend/modules/outliner/core.cljs +++ b/src/main/frontend/modules/outliner/core.cljs @@ -267,9 +267,30 @@ (recur (rest blocks) (first blocks)) matched))))) -(defn- compute-block-parent - [block parent target-block prev-hop top-level? sibling? get-new-id] +(defn- get-id + [x] (cond + (map? x) + (:db/id x) + + (vector? x) + (second x) + + :else + x)) + +(defn- compute-block-parent + [block parent target-block prev-hop top-level? sibling? get-new-id outliner-op] + (cond + ;; replace existing block + (and (= outliner-op :paste) + (string/blank? (:block/content target-block)) + (= (get-id (:block/parent target-block)) + (get-id (:block/parent block))) + (= (get-id (:block/left target-block)) + (get-id (:block/left block)))) + (get-id (:block/parent target-block)) + prev-hop (:db/id (:block/parent prev-hop)) @@ -455,7 +476,7 @@ (not= (:block/parent block) (:block/parent target-block))) prev-hop (if outdented-block? (find-outdented-block-prev-hop block blocks) nil) left-exists-in-blocks? (contains? ids (:db/id (:block/left block))) - parent (compute-block-parent block parent target-block prev-hop top-level? sibling? get-new-id) + parent (compute-block-parent block parent target-block prev-hop top-level? sibling? get-new-id outliner-op) left (compute-block-left blocks block left target-block prev-hop idx replace-empty-target? left-exists-in-blocks? get-new-id)] (cond-> (merge block {:block/uuid uuid