Browse Source

fix: replace empty target when paste cut blocks

Tienson Qin 2 years ago
parent
commit
0df201e7a8

+ 4 - 3
src/main/frontend/handler/editor.cljs

@@ -2000,7 +2000,8 @@
         paste-nested-blocks? (nested-blocks blocks)
         target-block-has-children? (db/has-children? (:block/uuid target-block))
         revert-cut-txs (get-revert-cut-tx blocks)
-        keep-uuid? (if (seq revert-cut-txs) true keep-uuid?)
+        cut-paste? (seq revert-cut-txs)
+        keep-uuid? (if cut-paste? true keep-uuid?)
         replace-empty-target? (if (and paste-nested-blocks? empty-target? target-block-has-children?)
                                 false
                                 true)
@@ -2019,8 +2020,7 @@
                    false
 
                    :else
-                   true)
-]
+                   true)]
 
     (when has-unsaved-edits
       (outliner-tx/transact!
@@ -2036,6 +2036,7 @@
                              (paste-block-cleanup block page exclude-properties format content-update-fn keep-uuid?))
                         blocks)
               result (outliner-core/insert-blocks! blocks' target-block' {:sibling? sibling?
+                                                                          :cut-paste? cut-paste?
                                                                           :outliner-op :paste
                                                                           :replace-empty-target? replace-empty-target?
                                                                           :keep-uuid? keep-uuid?})]

+ 6 - 2
src/main/frontend/modules/outliner/core.cljs

@@ -528,10 +528,11 @@
                     For example, if `blocks` are from internal copy, the uuids
                     need to be changed, but there's no need for drag & drop.
       `outliner-op`: what's the current outliner operation.
+      `cut-paste?`: whether it's pasted from cut blocks
       `replace-empty-target?`: If the `target-block` is an empty block, whether
                                to replace it, it defaults to be `false`.
     ``"
-  [blocks target-block {:keys [sibling? keep-uuid? outliner-op replace-empty-target?] :as opts}]
+  [blocks target-block {:keys [sibling? keep-uuid? outliner-op replace-empty-target? cut-paste?] :as opts}]
   {:pre [(seq blocks)
          (s/valid? ::block-map-or-entity target-block)]}
   (let [target-block' (get-target-block target-block)
@@ -587,7 +588,10 @@
                       (when-let [left (last (filter (fn [b] (= 1 (:block/level b))) tx))]
                         [{:block/uuid (tree/-get-id next)
                           :block/left (:db/id left)}]))
-            full-tx (util/concat-without-nil uuids-tx tx next-tx)]
+            cut-target-tx (when (and cut-paste? replace-empty-target?)
+                            [{:db/id (:db/id target-block')
+                              :block/uuid (:block/uuid (first blocks'))}])
+            full-tx (util/concat-without-nil uuids-tx tx next-tx cut-target-tx)]
         (when (and replace-empty-target? (state/editing?))
           (state/set-edit-content! (state/get-edit-input-id) (:block/content (first blocks))))
         {:tx-data full-tx