Don't allow deleting the block when there's only two blocks

pull/645/head
Tienson Qin 2020-09-07 09:10:44 +08:00
parent 06addeb113
commit 07856027eb
3 changed files with 36 additions and 30 deletions

View File

@ -408,11 +408,10 @@
selected-start (gobj/get node "selectionStart") selected-start (gobj/get node "selectionStart")
selected-end (gobj/get node "selectionEnd")] selected-end (gobj/get node "selectionEnd")]
(cond (cond
(not= selected-start selected-end) (not= selected-start selected-end)
nil nil
(zero? current-pos) (and (zero? current-pos))
(editor-handler/delete-block! state repo e) (editor-handler/delete-block! state repo e)
(and (> current-pos 1) (and (> current-pos 1)

View File

@ -950,6 +950,11 @@
nil) nil)
react))))) react)))))
(defn get-page-blocks-count
[repo page-id]
(when-let [db (get-conn repo)]
(count (d/datoms db :avet :block/page page-id))))
(defn get-page-directives-content (defn get-page-directives-content
[page] [page]
(let [blocks (get-page-blocks page)] (let [blocks (get-page-blocks page)]

View File

@ -713,7 +713,9 @@
[state repo e] [state repo e]
(let [{:keys [id block-id block-parent-id dummy? value pos format]} (get-state state)] (let [{:keys [id block-id block-parent-id dummy? value pos format]} (get-state state)]
(when block-id (when block-id
(do (when-let [page-id (:db/id (:block/page (db/entity [:block/uuid block-id])))]
(let [page-blocks-count (db/get-page-blocks-count repo page-id)]
(when (> page-blocks-count 2)
(util/stop e) (util/stop e)
;; delete block, edit previous block ;; delete block, edit previous block
(let [block (db/pull [:block/uuid block-id]) (let [block (db/pull [:block/uuid block-id])
@ -733,7 +735,7 @@
0)] 0)]
(save-block-if-changed! block new-value) (save-block-if-changed! block new-value)
(edit-block! (uuid sibling-block-id) (edit-block! (uuid sibling-block-id)
pos format id))))))))))) pos format id)))))))))))))
(defn delete-blocks! (defn delete-blocks!
[repo block-uuids] [repo block-uuids]