Преглед изворни кода

fix: block timestamps not updated when copy && paste

Fixes LOG-2705
Tienson Qin пре 2 година
родитељ
комит
5e5b7d0d01
2 измењених фајлова са 27 додато и 19 уклоњено
  1. 20 17
      src/main/frontend/handler/editor.cljs
  2. 7 2
      src/main/frontend/modules/outliner/core.cljs

+ 20 - 17
src/main/frontend/handler/editor.cljs

@@ -1949,7 +1949,8 @@
 
 (defn- paste-block-cleanup
   [repo block page exclude-properties format content-update-fn keep-uuid?]
-  (let [new-content
+  (let [db-based? (config/db-based-graph? (state/get-current-repo))
+        new-content
         (if content-update-fn
           (content-update-fn (:block/content block))
           (:block/content block))
@@ -1958,21 +1959,23 @@
           (not keep-uuid?) (property-file/remove-property-when-file-based repo format "id")
           true             (property-file/remove-property-when-file-based repo format "custom_id"))]
     (merge (apply dissoc block (conj (when-not keep-uuid? [:block/_refs]) :block/pre-block? :block/meta))
-           {:block/page {:db/id (:db/id page)}
-            :block/format format
-            ;; only file graphs exclude properties because db graphs don't put ids in properties
-            :block/properties (if (config/db-based-graph? (state/get-current-repo))
-                                (:block/properties block)
-                                (apply dissoc (:block/properties block)
-                                       (concat
-                                        (when-not keep-uuid? [:id])
-                                        [:custom_id :custom-id]
-                                        exclude-properties)))
-            :block/properties-text-values (apply dissoc (:block/properties-text-values block)
-                                                 (concat
-                                                  (when-not keep-uuid? [:id])
-                                                  exclude-properties))
-            :block/content new-content})))
+           (cond->
+            {:block/page {:db/id (:db/id page)}
+             :block/format format
+             ;; only file graphs exclude properties because db graphs don't put ids in properties
+             :block/properties (if db-based?
+                                 (:block/properties block)
+                                 (apply dissoc (:block/properties block)
+                                        (concat
+                                         (when-not keep-uuid? [:id])
+                                         [:custom_id :custom-id]
+                                         exclude-properties)))
+             :block/content new-content}
+             (not db-based?)
+             (assoc :block/properties-text-values (apply dissoc (:block/properties-text-values block)
+                                                  (concat
+                                                   (when-not keep-uuid? [:id])
+                                                   exclude-properties)))))))
 
 (defn- edit-last-block-after-inserted!
   [result]
@@ -2044,7 +2047,7 @@
        (let [format (or (:block/format target-block') (state/get-preferred-format))
              blocks' (map (fn [block]
                             (paste-block-cleanup repo block page exclude-properties format content-update-fn keep-uuid?))
-                          blocks)
+                       blocks)
              result (outliner-core/insert-blocks! blocks' target-block' {:sibling? sibling?
                                                                          :outliner-op :paste
                                                                          :replace-empty-target? replace-empty-target?

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

@@ -738,8 +738,10 @@
       `outliner-op`: what's the current outliner operation.
       `replace-empty-target?`: If the `target-block` is an empty block, whether
                                to replace it, it defaults to be `false`.
+      `update-timestamps?`: whether to update `blocks` timestamps.
     ``"
-  [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? update-timestamps?] :as opts
+                        :or {update-timestamps? true}}]
   {:pre [(seq blocks)
          (s/valid? ::block-map-or-entity target-block)]}
   (let [[target-block' sibling?] (get-target-block blocks target-block opts)
@@ -762,6 +764,8 @@
                      (blocks-with-ordered-list-props target-block sibling?))
                   (= outliner-op :paste)
                   fix-top-level-blocks
+                  update-timestamps?
+                  (mapv (fn [b] (block-with-timestamps (dissoc b :block/created-at :block/updated-at))))
                   true
                   (mapv block-with-timestamps))
         insert-opts {:sibling? sibling?
@@ -952,7 +956,8 @@
         (when-not move-parents-to-child?
           (let [first-block (first blocks)
                 {:keys [tx-data]} (insert-blocks blocks target-block {:sibling? sibling?
-                                                                      :outliner-op (or outliner-op :move-blocks)})]
+                                                                      :outliner-op (or outliner-op :move-blocks)
+                                                                      :update-timestamps? false})]
             (when (seq tx-data)
               (let [first-block-page (:db/id (:block/page first-block))
                     target-page (or (:db/id (:block/page target-block))