Skip to content

Commit

Permalink
fix: DELETE key can result in wrong tree relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed May 6, 2021
1 parent 825c157 commit e3b3257
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/main/frontend/db/outliner.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
@conn parent-id left-id)]
(ffirst r)))

(defn get-first-child
[conn parent-id]
(get-by-parent-&-left conn parent-id parent-id))

;; key [:block/children parent-id]

(def get-by-parent-id
Expand Down
26 changes: 21 additions & 5 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
[lambdaisland.glogi :as log]
[cljs.core.match :refer-macros [match]]
[frontend.modules.outliner.core :as outliner-core]
[frontend.db.outliner :as outliner-db]
[frontend.modules.outliner.tree :as tree]
[frontend.debug :as debug]))

Expand Down Expand Up @@ -2070,11 +2071,26 @@
repo (state/get-current-repo)]
(when current-block
(if (and end? current-block)
(when-let [right (outliner-core/get-right-node (outliner-core/block current-block))]
(when-not (db/has-children? repo (tree/-get-id right))
(let [right-block (:data right)]
(delete-block-aux! right-block false false)
(state/set-edit-content! input-id (str value "" (:block/content right-block)))
(let [right (outliner-core/get-right-node (outliner-core/block current-block))
current-block-has-children? (db/has-children? repo (:block/uuid current-block))
collapsed? (:collapsed (:block/properties current-block))
first-child (outliner-db/get-first-child (db/get-conn repo false) (:db/id current-block))
next-block (if (or collapsed? (not current-block-has-children?))
(:data right)
first-child)
first-child-has-children? (and first-child
(db/has-children? repo (:block/uuid first-child)))]
(cond
(and collapsed? right (db/has-children? repo (tree/-get-id right)))
nil

(and (not collapsed?) first-child (db/has-children? repo (:block/uuid first-child)))
nil

:else
(do
(delete-block-aux! next-block false false)
(state/set-edit-content! input-id (str value "" (:block/content next-block)))
(util/move-cursor-to input current-pos))))
(delete-and-update input current-pos (inc current-pos))))))

Expand Down

0 comments on commit e3b3257

Please sign in to comment.