mirror of
https://github.com/logseq/logseq.git
synced 2026-05-04 19:06:21 +00:00
refactor: remove dummy block
This commit is contained in:
@@ -143,14 +143,12 @@
|
||||
(state/set-cursor-range! (util/caret-range node))))
|
||||
|
||||
(defn restore-cursor-pos!
|
||||
([id markup]
|
||||
(restore-cursor-pos! id markup false))
|
||||
([id markup dummy?]
|
||||
(when-let [node (gdom/getElement (str id))]
|
||||
(when-let [cursor-range (state/get-cursor-range)]
|
||||
(when-let [range cursor-range]
|
||||
(let [pos (diff/find-position markup range)]
|
||||
(util/set-caret-pos! node pos)))))))
|
||||
[id markup]
|
||||
(when-let [node (gdom/getElement (str id))]
|
||||
(when-let [cursor-range (state/get-cursor-range)]
|
||||
(when-let [range cursor-range]
|
||||
(let [pos (diff/find-position markup range)]
|
||||
(util/set-caret-pos! node pos))))))
|
||||
|
||||
(defn highlight-block!
|
||||
[block-uuid]
|
||||
@@ -288,7 +286,7 @@
|
||||
|
||||
(defn- wrap-parse-block
|
||||
[{:block/keys [content format parent left page uuid pre-block?] :as block}]
|
||||
(let [block (or (db/pull (:db/id block)) block)
|
||||
(let [block (or (and (:db/id block) (db/pull (:db/id block))) block)
|
||||
properties (:block/properties block)
|
||||
real-content (:block/content block)
|
||||
content (if (and (seq properties) real-content (not= real-content content))
|
||||
@@ -330,10 +328,10 @@
|
||||
(select-keys properties property/built-in-properties)
|
||||
(:block/properties block))]
|
||||
(-> block
|
||||
(dissoc :block/top?
|
||||
:block/block-refs-count)
|
||||
(assoc :block/content content
|
||||
:block/properties new-properties))))
|
||||
(dissoc :block/top?
|
||||
:block/block-refs-count)
|
||||
(assoc :block/content content
|
||||
:block/properties new-properties))))
|
||||
|
||||
(defn- save-block-inner!
|
||||
[repo block value {:keys [refresh?]
|
||||
@@ -390,7 +388,6 @@
|
||||
[config current-block new-block sibling?]
|
||||
(let [ref-top-block? (and (:ref? config)
|
||||
(not (:ref-child? config)))
|
||||
dummy? (:block/dummy? current-block)
|
||||
[current-node new-node]
|
||||
(mapv outliner-core/block [current-block new-block])
|
||||
has-children? (db/has-children? (state/get-current-repo)
|
||||
@@ -464,7 +461,7 @@
|
||||
|
||||
(defn insert-new-block-before-block-aux!
|
||||
[config
|
||||
{:block/keys [uuid content repo format page dummy?]
|
||||
{:block/keys [uuid content repo format page]
|
||||
db-id :db/id
|
||||
:as block}
|
||||
value
|
||||
@@ -494,7 +491,7 @@
|
||||
|
||||
(defn insert-new-block-aux!
|
||||
[config
|
||||
{:block/keys [uuid content repo format page dummy?]
|
||||
{:block/keys [uuid content repo format page]
|
||||
db-id :db/id
|
||||
:as block}
|
||||
value
|
||||
@@ -522,7 +519,7 @@
|
||||
:data [current-block next-block]}]
|
||||
(db/refresh! repo opts)))]
|
||||
(do
|
||||
(if (or dummy? (:ref? config) (not sibling?))
|
||||
(if (or (:ref? config) (not sibling?))
|
||||
(refresh-fn)
|
||||
(do
|
||||
(profile "update cache " (update-cache-for-block-insert! repo config block blocks))
|
||||
@@ -543,14 +540,13 @@
|
||||
|
||||
(defn get-state
|
||||
[]
|
||||
(let [[{:keys [on-hide block block-id block-parent-id dummy? format sidebar?]} id config] (state/get-editor-args)
|
||||
(let [[{:keys [on-hide block block-id block-parent-id format sidebar?]} id config] (state/get-editor-args)
|
||||
node (gdom/getElement id)]
|
||||
(when node
|
||||
(let [value (gobj/get node "value")
|
||||
pos (gobj/get node "selectionStart")]
|
||||
{:config config
|
||||
:on-hide on-hide
|
||||
:dummy? dummy?
|
||||
:sidebar? sidebar?
|
||||
:format format
|
||||
:id id
|
||||
@@ -667,7 +663,7 @@
|
||||
content))
|
||||
|
||||
(defn check
|
||||
[{:block/keys [uuid marker content format dummy? repeated?] :as block}]
|
||||
[{:block/keys [uuid marker content format repeated?] :as block}]
|
||||
(let [new-content (string/replace-first content marker "DONE")
|
||||
new-content (->
|
||||
(if repeated?
|
||||
@@ -677,7 +673,7 @@
|
||||
(save-block-if-changed! block new-content)))
|
||||
|
||||
(defn uncheck
|
||||
[{:block/keys [uuid marker content format dummy?] :as block}]
|
||||
[{:block/keys [uuid marker content format] :as block}]
|
||||
(let [marker (if (= :now (state/get-preferred-workflow))
|
||||
"LATER"
|
||||
"TODO")
|
||||
@@ -720,13 +716,13 @@
|
||||
|
||||
|
||||
(defn set-marker
|
||||
[{:block/keys [uuid marker content format dummy? properties] :as block} new-marker]
|
||||
[{:block/keys [uuid marker content format properties] :as block} new-marker]
|
||||
(let [new-content (-> (string/replace-first content marker new-marker)
|
||||
(with-marker-time format new-marker))]
|
||||
(save-block-if-changed! block new-content)))
|
||||
|
||||
(defn set-priority
|
||||
[{:block/keys [uuid marker priority content dummy?] :as block} new-priority]
|
||||
[{:block/keys [uuid marker priority content] :as block} new-priority]
|
||||
(let [new-content (string/replace-first content
|
||||
(util/format "[#%s]" priority)
|
||||
(util/format "[#%s]" new-priority))]
|
||||
@@ -749,21 +745,20 @@
|
||||
(util/nth-safe blocks idx))))))
|
||||
|
||||
(defn delete-block-aux!
|
||||
[{:block/keys [uuid content repo refs] :as block} dummy? children?]
|
||||
(when-not dummy?
|
||||
(let [repo (or repo (state/get-current-repo))
|
||||
block (db/pull repo '[*] [:block/uuid uuid])]
|
||||
(when block
|
||||
(->
|
||||
(outliner-core/block block)
|
||||
(outliner-core/delete-node children?))
|
||||
(db/refresh! repo {:key :block/change :data [block]})))))
|
||||
[{:block/keys [uuid content repo refs] :as block} children?]
|
||||
(let [repo (or repo (state/get-current-repo))
|
||||
block (db/pull repo '[*] [:block/uuid uuid])]
|
||||
(when block
|
||||
(->
|
||||
(outliner-core/block block)
|
||||
(outliner-core/delete-node children?))
|
||||
(db/refresh! repo {:key :block/change :data [block]}))))
|
||||
|
||||
(defn delete-block!
|
||||
([repo e]
|
||||
(delete-block! repo e true))
|
||||
([repo e delete-children?]
|
||||
(let [{:keys [id block-id block-parent-id dummy? value format]} (get-state)]
|
||||
(let [{:keys [id block-id block-parent-id value format]} (get-state)]
|
||||
(when block-id
|
||||
(let [page-id (:db/id (:block/page (db/entity [:block/uuid block-id])))
|
||||
page-blocks-count (and page-id (db/get-page-blocks-count repo page-id))]
|
||||
@@ -779,7 +774,7 @@
|
||||
(when-not (and has-children? left-has-children?)
|
||||
(let [block-parent (gdom/getElement block-parent-id)
|
||||
sibling-block (get-prev-block-non-collapsed block-parent)]
|
||||
(delete-block-aux! block dummy? delete-children?)
|
||||
(delete-block-aux! block delete-children?)
|
||||
(when (and repo sibling-block)
|
||||
(when-let [sibling-block-id (dom/attr sibling-block "blockid")]
|
||||
(when-let [block (db/pull repo '[*] [:block/uuid (uuid sibling-block-id)])]
|
||||
@@ -829,7 +824,7 @@
|
||||
(let [start-node (outliner-core/block (first blocks))
|
||||
end-node (get-top-level-end-node blocks)]
|
||||
(if (= start-node end-node)
|
||||
(delete-block-aux! (first blocks) false true)
|
||||
(delete-block-aux! (first blocks) true)
|
||||
(when (outliner-core/delete-nodes start-node end-node lookup-refs)
|
||||
(let [opts {:key :block/change
|
||||
:data blocks}]
|
||||
@@ -1154,7 +1149,7 @@
|
||||
(when-let [block (db/pull [:block/uuid block-id])]
|
||||
(let [content (:block/content block)]
|
||||
(common-handler/copy-to-clipboard-without-id-property! (:block/format block) content)
|
||||
(delete-block-aux! block false true))))
|
||||
(delete-block-aux! block true))))
|
||||
|
||||
(defn clear-last-selected-block!
|
||||
[]
|
||||
@@ -1230,9 +1225,8 @@
|
||||
(db-model/query-block-by-uuid block-or-uuid) block-or-uuid)
|
||||
format (:block/format block)]
|
||||
(save-block! {:block block :repo repo :format format} content)))
|
||||
([{:keys [format block repo dummy?] :as state} value]
|
||||
(when (or (:db/id (db/entity repo [:block/uuid (:block/uuid block)]))
|
||||
dummy?)
|
||||
([{:keys [format block repo] :as state} value]
|
||||
(when (:db/id (db/entity repo [:block/uuid (:block/uuid block)]))
|
||||
(save-block-aux! block value format {}))))
|
||||
|
||||
(defn save-current-block!
|
||||
@@ -1904,10 +1898,8 @@
|
||||
(defn- get-block-tree-insert-pos-at-point
|
||||
"return [target-block sibling? delete-editing-block? editing-block]"
|
||||
[]
|
||||
(when-let [editing-block (or (db/pull (:db/id (state/get-edit-block)))
|
||||
(when (:block/dummy? (state/get-edit-block)) (state/get-edit-block)))]
|
||||
(let [dummy? (:block/dummy? editing-block)
|
||||
input (gdom/getElement (state/get-edit-input-id))
|
||||
(when-let [editing-block (db/pull (:db/id (state/get-edit-block)))]
|
||||
(let [input (gdom/getElement (state/get-edit-input-id))
|
||||
pos (util/get-input-pos input)
|
||||
value (:value (get-state))
|
||||
[fst-block-text snd-block-text] (compute-fst-snd-block-text value pos)
|
||||
@@ -1921,15 +1913,8 @@
|
||||
has-children? (db/has-children? (state/get-current-repo)
|
||||
(:block/uuid editing-block))
|
||||
collapsed? (:collapsed (:block/properties editing-block))]
|
||||
(conj (match (mapv boolean [dummy? (seq fst-block-text) (seq snd-block-text)
|
||||
(conj (match (mapv boolean [(seq fst-block-text) (seq snd-block-text)
|
||||
block-self? has-children? (= parent left) collapsed?])
|
||||
;; if editing-block is dummy, insert after page-block
|
||||
[true false false _ _ _ _]
|
||||
[parent-block false true]
|
||||
|
||||
[true _ _ _ _ _ _]
|
||||
[parent-block false false]
|
||||
|
||||
;; when zoom at editing-block
|
||||
[false _ _ true _ _ _]
|
||||
[editing-block false false]
|
||||
@@ -2269,7 +2254,7 @@
|
||||
|
||||
:else
|
||||
(do
|
||||
(delete-block-aux! next-block false false)
|
||||
(delete-block-aux! next-block false)
|
||||
(state/set-edit-content! input-id (str value "" (:block/content next-block)))
|
||||
(util/move-cursor-to input current-pos)))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user