mirror of https://github.com/logseq/logseq
Don't allow deleting the block when there's only two blocks
parent
06addeb113
commit
07856027eb
|
@ -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)
|
||||||
|
|
|
@ -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)]
|
||||||
|
|
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue