Răsfoiți Sursa

Move cut-paste? logic to paste handler

Tienson Qin 2 ani în urmă
părinte
comite
1be20c8f11
2 a modificat fișierele cu 18 adăugiri și 14 ștergeri
  1. 3 13
      src/main/frontend/handler/editor.cljs
  2. 15 1
      src/main/frontend/handler/paste.cljs

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

@@ -1959,15 +1959,6 @@
   (let [ids (set (map :db/id blocks))]
   (let [ids (set (map :db/id blocks))]
     (some? (some #(ids (:db/id (:block/parent %))) blocks))))
     (some? (some #(ids (:db/id (:block/parent %))) blocks))))
 
 
-(defn- get-revert-cut-tx
-  [blocks]
-  (let [{:keys [retracted-block-ids revert-tx]} (get-in @state/state [:editor/last-replace-ref-content-tx (state/get-current-repo)])
-        recent-cut-block-ids (->> retracted-block-ids (map second) (set))]
-    (state/set-state! [:editor/last-replace-ref-content-tx (state/get-current-repo)] nil)
-    (when (and (= (set (map :block/uuid blocks)) recent-cut-block-ids)
-               (seq revert-tx))
-      revert-tx)))
-
 (defn paste-blocks
 (defn paste-blocks
   "Given a vec of blocks, insert them into the target page.
   "Given a vec of blocks, insert them into the target page.
    keep-uuid?: if true, keep the uuid provided in the block structure."
    keep-uuid?: if true, keep the uuid provided in the block structure."
@@ -1975,7 +1966,9 @@
                   exclude-properties
                   exclude-properties
                   target-block
                   target-block
                   sibling?
                   sibling?
-                  keep-uuid?]
+                  keep-uuid?
+                  cut-paste?
+                  revert-cut-txs]
            :or {exclude-properties []}}]
            :or {exclude-properties []}}]
   (let [editing-block (when-let [editing-block (state/get-edit-block)]
   (let [editing-block (when-let [editing-block (state/get-edit-block)]
                         (some-> (db/pull [:block/uuid (:block/uuid editing-block)])
                         (some-> (db/pull [:block/uuid (:block/uuid editing-block)])
@@ -1990,9 +1983,6 @@
         empty-target? (string/blank? (:block/content target-block))
         empty-target? (string/blank? (:block/content target-block))
         paste-nested-blocks? (nested-blocks blocks)
         paste-nested-blocks? (nested-blocks blocks)
         target-block-has-children? (db/has-children? (:block/uuid target-block))
         target-block-has-children? (db/has-children? (:block/uuid target-block))
-        revert-cut-txs (get-revert-cut-tx blocks)
-        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?)
         replace-empty-target? (if (and paste-nested-blocks? empty-target? target-block-has-children?)
                                 false
                                 false
                                 true)
                                 true)

+ 15 - 1
src/main/frontend/handler/paste.cljs

@@ -105,6 +105,15 @@
   [text]
   [text]
   (boolean (util/safe-re-find #"(?m)^\s*\*+\s+" text)))
   (boolean (util/safe-re-find #"(?m)^\s*\*+\s+" text)))
 
 
+(defn- get-revert-cut-tx
+  "Get reverted previous cut tx when paste"
+  [blocks]
+  (let [{:keys [retracted-block-ids revert-tx]} (get-in @state/state [:editor/last-replace-ref-content-tx (state/get-current-repo)])
+        recent-cut-block-ids (->> retracted-block-ids (map second) (set))]
+    (state/set-state! [:editor/last-replace-ref-content-tx (state/get-current-repo)] nil)
+    (when (= (set (map :block/uuid blocks)) recent-cut-block-ids)
+      (seq revert-tx))))
+
 (defn- paste-copied-blocks-or-text
 (defn- paste-copied-blocks-or-text
   ;; todo: logseq/whiteboard-shapes is now text/html
   ;; todo: logseq/whiteboard-shapes is now text/html
   [text e html]
   [text e html]
@@ -120,7 +129,12 @@
                               (commands/simple-insert! input-id text nil)))
                               (commands/simple-insert! input-id text nil)))
            internal-paste? (seq copied-blocks)]
            internal-paste? (seq copied-blocks)]
        (if internal-paste?
        (if internal-paste?
-         (editor-handler/paste-blocks copied-blocks {})
+         (let [revert-cut-tx (get-revert-cut-tx copied-blocks)
+               cut-paste? (boolean (seq revert-cut-tx))
+               keep-uuid? cut-paste?]
+           (editor-handler/paste-blocks copied-blocks {:revert-cut-tx revert-cut-tx
+                                                       :cut-paste? cut-paste?
+                                                       :keep-uuid? keep-uuid?}))
          (let [shape-refs-text (when (and (not (string/blank? html))
          (let [shape-refs-text (when (and (not (string/blank? html))
                                           (get-whiteboard-tldr-from-text html))
                                           (get-whiteboard-tldr-from-text html))
                                  ;; text should always be prepared block-ref generated in tldr
                                  ;; text should always be prepared block-ref generated in tldr