From 0df201e7a899b6433365cdc42512d360f770dedf Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 15 May 2023 21:46:15 +0800 Subject: [PATCH] fix: replace empty target when paste cut blocks --- src/main/frontend/handler/editor.cljs | 7 ++++--- src/main/frontend/modules/outliner/core.cljs | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 0b76dc7054..5fafc15c96 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/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?})] diff --git a/src/main/frontend/modules/outliner/core.cljs b/src/main/frontend/modules/outliner/core.cljs index ab66d8c069..8066276f5c 100644 --- a/src/main/frontend/modules/outliner/core.cljs +++ b/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