mirror of
https://github.com/logseq/logseq.git
synced 2026-05-03 10:26:35 +00:00
Merge branch 'master' into feat/integration-plugins-core
This commit is contained in:
@@ -1903,7 +1903,7 @@
|
||||
(util/cursor-move-forward input 2)))
|
||||
|
||||
(defn- get-block-tree-insert-pos-at-point
|
||||
"return [target-block sibling?]"
|
||||
"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)))]
|
||||
@@ -1925,34 +1925,85 @@
|
||||
(conj (match (mapv boolean [dummy? (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]
|
||||
[parent-block false false]
|
||||
|
||||
;; when zoom at editing-block
|
||||
[false _ _ true _ _ _]
|
||||
[editing-block false]
|
||||
[editing-block false false]
|
||||
|
||||
;; insert after editing-block
|
||||
[false true _ false true _ false]
|
||||
[editing-block false]
|
||||
[editing-block false false]
|
||||
[false true _ false true _ true]
|
||||
[editing-block true]
|
||||
[editing-block true false]
|
||||
[false true _ false false _ _]
|
||||
[editing-block true]
|
||||
[editing-block true false]
|
||||
[false false false false true _ false]
|
||||
[editing-block false]
|
||||
[editing-block false false]
|
||||
[false false false false true _ true]
|
||||
[editing-block true]
|
||||
[editing-block true false]
|
||||
[false false false false false _ _]
|
||||
[editing-block true]
|
||||
[editing-block true true]
|
||||
|
||||
;; insert before editing-block
|
||||
[false false true false _ true _]
|
||||
[parent-block false]
|
||||
[parent-block false false]
|
||||
[false false true false _ false _]
|
||||
[left-block true])
|
||||
[left-block true false])
|
||||
editing-block))))
|
||||
|
||||
(defn- paste-block-tree-at-point-edit-aux
|
||||
[uuid file page exclude-properties format content-update-fn]
|
||||
(fn [block]
|
||||
(outliner-core/block
|
||||
(let [[new-content new-title]
|
||||
(if content-update-fn
|
||||
(let [new-content (content-update-fn (:block/content block))
|
||||
new-title (or (->> (mldoc/->edn
|
||||
(str (case format
|
||||
:markdown "- "
|
||||
:org "* ")
|
||||
(if (seq (:block/title block)) "" "\n")
|
||||
new-content)
|
||||
(mldoc/default-config format))
|
||||
(ffirst)
|
||||
(second)
|
||||
(:title))
|
||||
(:block/title block))]
|
||||
[new-content new-title])
|
||||
[(:block/content block) (:block/title block)])
|
||||
new-content
|
||||
(->> new-content
|
||||
(property/remove-property format "id")
|
||||
(property/remove-property format "custom_id"))]
|
||||
(conj {:block/uuid uuid
|
||||
:block/page (select-keys page [:db/id])
|
||||
:block/file (select-keys file [:db/id])
|
||||
:block/format format
|
||||
:block/properties (apply dissoc (:block/properties block)
|
||||
(concat [:id :custom_id :custom-id]
|
||||
exclude-properties))
|
||||
:block/meta (dissoc (:block/meta block) :start-pos :end-pos)
|
||||
:block/content new-content
|
||||
:block/title new-title}
|
||||
(dissoc block
|
||||
:block/pre-block?
|
||||
:block/uuid
|
||||
:block/page
|
||||
:block/file
|
||||
:db/id
|
||||
:block/left
|
||||
:block/parent
|
||||
:block/format
|
||||
:block/properties
|
||||
:block/meta
|
||||
:block/content
|
||||
:block/title))))))
|
||||
|
||||
(defn- paste-block-tree-at-point
|
||||
([tree exclude-properties] (paste-block-tree-at-point tree exclude-properties nil))
|
||||
([tree exclude-properties content-update-fn]
|
||||
@@ -1961,7 +2012,8 @@
|
||||
(db/entity [:block/original-name (state/get-current-page)])
|
||||
(:block/page (db/entity (:db/id (state/get-edit-block)))))
|
||||
file (:block/file page)]
|
||||
(when-let [[target-block sibling? editing-block] (get-block-tree-insert-pos-at-point)]
|
||||
(when-let [[target-block sibling? delete-editing-block? editing-block]
|
||||
(get-block-tree-insert-pos-at-point)]
|
||||
(let [target-block (outliner-core/block target-block)
|
||||
editing-block (outliner-core/block editing-block)
|
||||
format (or (:block/format target-block) (state/get-preferred-format))
|
||||
@@ -1975,52 +2027,15 @@
|
||||
(recur (zip/next loc))
|
||||
(let [uuid (random-uuid)]
|
||||
(swap! new-block-uuids (fn [acc uuid] (conj acc uuid)) uuid)
|
||||
|
||||
(recur (zip/next (zip/edit
|
||||
loc
|
||||
#(outliner-core/block
|
||||
(let [[new-content new-title]
|
||||
(if content-update-fn
|
||||
(let [new-content (content-update-fn (:block/content %))
|
||||
new-title (or (:title (second (ffirst
|
||||
(mldoc/->edn (str (case format
|
||||
:markdown "- "
|
||||
:org "* ")
|
||||
(if (seq (:block/title %)) "" "\n")
|
||||
new-content)
|
||||
(mldoc/default-config format)))))
|
||||
(:block/title %))]
|
||||
[new-content new-title])
|
||||
[(:block/content %) (:block/title %)])
|
||||
new-content
|
||||
(->> new-content
|
||||
(property/remove-property format "id")
|
||||
(property/remove-property format "custom_id"))]
|
||||
(conj {:block/uuid uuid
|
||||
:block/page (select-keys page [:db/id])
|
||||
:block/file (select-keys file [:db/id])
|
||||
:block/format format
|
||||
:block/properties (apply dissoc (:block/properties %)
|
||||
(concat [:id :custom_id :custom-id]
|
||||
exclude-properties))
|
||||
:block/meta (dissoc (:block/meta %) :start-pos :end-pos)
|
||||
:block/content new-content
|
||||
:block/title new-title}
|
||||
(dissoc %
|
||||
:block/pre-block?
|
||||
:block/uuid
|
||||
:block/page
|
||||
:block/file
|
||||
:db/id
|
||||
:block/left
|
||||
:block/parent
|
||||
:block/format
|
||||
:block/properties
|
||||
:block/meta
|
||||
:block/content
|
||||
:block/title))))))))))))
|
||||
(paste-block-tree-at-point-edit-aux
|
||||
uuid file page exclude-properties format content-update-fn)))))))))
|
||||
_ (outliner-core/save-node editing-block)
|
||||
_ (outliner-core/insert-nodes metadata-replaced-blocks target-block sibling?)
|
||||
_ (when delete-editing-block?
|
||||
(when-let [id (:db/id (outliner-core/get-data editing-block))]
|
||||
(outliner-core/delete-node (outliner-core/block (db/pull id)) true)))
|
||||
new-blocks (db/pull-many repo '[*] (map (fn [id] [:block/uuid id]) @new-block-uuids))]
|
||||
(db/refresh! repo {:key :block/insert :data new-blocks}))))))
|
||||
|
||||
@@ -2039,6 +2054,7 @@
|
||||
sorted-blocks (tree/sort-blocks blocks-exclude-root root-block)
|
||||
result-blocks (if including-parent? sorted-blocks (drop 1 sorted-blocks))
|
||||
tree (blocks-vec->tree result-blocks)]
|
||||
(insert-command! id "" format {})
|
||||
(paste-block-tree-at-point tree [:template :including-parent]
|
||||
(fn [content]
|
||||
(->> content
|
||||
@@ -2046,7 +2062,6 @@
|
||||
(property/remove-property format "including-parent")
|
||||
template/resolve-dynamic-template!)))
|
||||
(clear-when-saved!)
|
||||
(insert-command! id "" format {})
|
||||
(db/refresh! repo {:key :block/insert :data [(db/pull db-id)]}))
|
||||
(when-let [input (gdom/getElement id)]
|
||||
(.focus input))))
|
||||
|
||||
Reference in New Issue
Block a user