mirror of https://github.com/logseq/logseq
Don't allow deleting the block when there's only two blocks
parent
06addeb113
commit
07856027eb
|
@ -90,8 +90,8 @@
|
|||
(fn [chosen _click?]
|
||||
(state/set-editor-show-page-search false)
|
||||
(editor-handler/insert-command! id
|
||||
(util/format "#%s" (if (string/includes? chosen " ")
|
||||
(str "[[" chosen "]]")
|
||||
(util/format "#%s" (if (string/includes? chosen " ")
|
||||
(str "[[" chosen "]]")
|
||||
chosen))
|
||||
format
|
||||
{:last-pattern (str "#" (if @editor-handler/*selected-text "" q))}))
|
||||
|
@ -408,11 +408,10 @@
|
|||
selected-start (gobj/get node "selectionStart")
|
||||
selected-end (gobj/get node "selectionEnd")]
|
||||
(cond
|
||||
|
||||
(not= selected-start selected-end)
|
||||
nil
|
||||
|
||||
(zero? current-pos)
|
||||
(and (zero? current-pos))
|
||||
(editor-handler/delete-block! state repo e)
|
||||
|
||||
(and (> current-pos 1)
|
||||
|
@ -449,7 +448,7 @@
|
|||
|
||||
:else
|
||||
nil))
|
||||
|
||||
|
||||
;; deleting hashtag
|
||||
(and (= deleted "#") (state/get-editor-show-page-search-hashtag))
|
||||
(state/set-editor-show-page-search-hashtag false)
|
||||
|
@ -478,7 +477,7 @@
|
|||
(commands/handle-step [:editor/search-page])
|
||||
(reset! commands/*slash-caret-pos (util/get-caret-pos input)))
|
||||
|
||||
(and
|
||||
(and
|
||||
(not= key-code 8) ;; backspace
|
||||
(or
|
||||
(editor-handler/surround-by? input "#" " ")
|
||||
|
@ -488,7 +487,7 @@
|
|||
(commands/handle-step [:editor/search-page-hashtag])
|
||||
(state/set-last-pos! (:pos (util/get-caret-pos input)))
|
||||
(reset! commands/*slash-caret-pos (util/get-caret-pos input)))
|
||||
|
||||
|
||||
(and
|
||||
(= key " ")
|
||||
(state/get-editor-show-page-search-hashtag))
|
||||
|
|
|
@ -950,6 +950,11 @@
|
|||
nil)
|
||||
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
|
||||
[page]
|
||||
(let [blocks (get-page-blocks page)]
|
||||
|
|
|
@ -289,8 +289,8 @@
|
|||
(reset! last-child-end-pos old-end-pos)))
|
||||
|
||||
(cond->
|
||||
{:block/uuid uuid
|
||||
:block/meta new-meta}
|
||||
{:block/uuid uuid
|
||||
:block/meta new-meta}
|
||||
(and (some? indent-left?) (not @next-leq-level?))
|
||||
(assoc :block/level (if indent-left? (dec level) (inc level)))
|
||||
(and new-content (not @next-leq-level?))
|
||||
|
@ -713,27 +713,29 @@
|
|||
[state repo e]
|
||||
(let [{:keys [id block-id block-parent-id dummy? value pos format]} (get-state state)]
|
||||
(when block-id
|
||||
(do
|
||||
(util/stop e)
|
||||
;; delete block, edit previous block
|
||||
(let [block (db/pull [:block/uuid block-id])
|
||||
block-parent (gdom/getElement block-parent-id)
|
||||
sibling-block (get-prev-block-non-collapsed block-parent)]
|
||||
(delete-block-aux! block dummy?)
|
||||
(when sibling-block
|
||||
(when-let [sibling-block-id (d/attr sibling-block "blockid")]
|
||||
(when repo
|
||||
(when-let [block (db/pull repo '[*] [:block/uuid (uuid sibling-block-id)])]
|
||||
(let [original-content (util/trim-safe (:block/content block))
|
||||
new-value (str original-content value)
|
||||
pos (max
|
||||
(if original-content
|
||||
(utf8/length (utf8/encode (text/remove-level-spaces original-content format)))
|
||||
0)
|
||||
0)]
|
||||
(save-block-if-changed! block new-value)
|
||||
(edit-block! (uuid sibling-block-id)
|
||||
pos format id)))))))))))
|
||||
(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)
|
||||
;; delete block, edit previous block
|
||||
(let [block (db/pull [:block/uuid block-id])
|
||||
block-parent (gdom/getElement block-parent-id)
|
||||
sibling-block (get-prev-block-non-collapsed block-parent)]
|
||||
(delete-block-aux! block dummy?)
|
||||
(when sibling-block
|
||||
(when-let [sibling-block-id (d/attr sibling-block "blockid")]
|
||||
(when repo
|
||||
(when-let [block (db/pull repo '[*] [:block/uuid (uuid sibling-block-id)])]
|
||||
(let [original-content (util/trim-safe (:block/content block))
|
||||
new-value (str original-content value)
|
||||
pos (max
|
||||
(if original-content
|
||||
(utf8/length (utf8/encode (text/remove-level-spaces original-content format)))
|
||||
0)
|
||||
0)]
|
||||
(save-block-if-changed! block new-value)
|
||||
(edit-block! (uuid sibling-block-id)
|
||||
pos format id)))))))))))))
|
||||
|
||||
(defn delete-blocks!
|
||||
[repo block-uuids]
|
||||
|
|
Loading…
Reference in New Issue