浏览代码

fix(api): insert as first child when current node is first child

charlie 3 年之前
父节点
当前提交
8d8c5624ac
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7 2
      src/main/frontend/handler/editor.cljs

+ 7 - 2
src/main/frontend/handler/editor.cljs

@@ -707,8 +707,13 @@
                             (assoc :block/uuid (or custom-uuid (db/new-block-id))))
               [block-m sibling?] (cond
                                    before?
-                                   (let [block (db/pull (:db/id (:block/left block)))
-                                         sibling? (if (:block/name block) false sibling?)]
+                                   (let [first-child? (->> [:block/parent :block/left]
+                                                           (map #(:db/id (get block %)))
+                                                           (apply =))
+                                         block (db/pull (:db/id (:block/left block)))
+                                         sibling? (if (or first-child? ;; insert as first child
+                                                          (:block/name block))
+                                                    false sibling?)]
                                      [block sibling?])
 
                                    sibling?