Browse Source

refactor: move ordered list logic into the unified 'insert-blocks transaction phase

charlie 2 years ago
parent
commit
7b4349aed9

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

@@ -587,9 +587,7 @@
                     {:ok-handler
                      (fn [last-block]
                        (clear-when-saved!)
-                       (edit-block! last-block 0 id)
-                       (when-let [order-list-type (and (own-order-list? block) (get-block-own-order-list-type block))]
-                         (set-block-own-order-list-type! last-block order-list-type)))}))))
+                       (edit-block! last-block 0 id))}))))
    (state/set-editor-op! nil)))
 
 (defn api-insert-new-block!

+ 19 - 3
src/main/frontend/modules/outliner/core.cljs

@@ -409,6 +409,18 @@
            last
            rest))))
 
+(defn blocks-with-?ordered-list-props
+  [blocks target-block sibling?]
+  (letfn [(list-type-fn [b] (some-> b :block/properties :logseq.order-list-type))]
+    (if-let [list-type (and sibling? target-block (list-type-fn target-block))]
+      (mapv
+        (fn [block]
+          (cond-> block
+            (some? (:block/properties block))
+            (assoc-in [:block/properties :logseq.order-list-type] list-type)))
+        blocks)
+      blocks)))
+
 ;;; ### insert-blocks, delete-blocks, move-blocks
 
 (defn fix-top-level-blocks
@@ -519,6 +531,7 @@
                                      (> (count blocks) 1)
                                      (not move?)))
         blocks' (blocks-with-level blocks)
+        blocks' (blocks-with-?ordered-list-props blocks' target-block sibling?)
         blocks' (if (= outliner-op :paste)
                   (fix-top-level-blocks blocks')
                   blocks')
@@ -527,7 +540,8 @@
                      :keep-uuid? keep-uuid?
                      :move? move?
                      :outliner-op outliner-op}
-        tx (insert-blocks-aux blocks' target-block' insert-opts)]
+        tx (insert-blocks-aux blocks' target-block' insert-opts)
+        _ (prn "====>>> op:insert-blocks tx#" tx)]
     (if (some (fn [b] (or (nil? (:block/parent b)) (nil? (:block/left b)))) tx)
       (do
         (state/pub-event! [:capture-error {:error "Outliner invalid structure"
@@ -559,8 +573,10 @@
             full-tx (util/concat-without-nil uuids-tx tx next-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
-         :blocks tx}))))
+        (let [output {:tx-data full-tx
+                      :blocks  tx}]
+          (prn "==>>> op:insert-blocks full-tx#" output)
+          output)))))
 
 (defn- build-move-blocks-next-tx
   [blocks non-consecutive-blocks?]