mirror of
https://github.com/logseq/logseq.git
synced 2026-05-28 06:34:34 +00:00
fix: handle the case when both blocks are referenced
This commit is contained in:
@@ -361,8 +361,8 @@
|
||||
(assoc :block/uuid (:block/uuid block)))
|
||||
opts' (merge opts (cond-> {:outliner-op :save-block}
|
||||
uuid-changed?
|
||||
(assoc :uuid-changed {:from (:block/uuid block)
|
||||
:to original-uuid})))]
|
||||
(assoc :uuid-changed {:kept (:block/uuid block)
|
||||
:deleted original-uuid})))]
|
||||
(outliner-tx/transact!
|
||||
opts'
|
||||
(outliner-core/save-block! block'))
|
||||
@@ -390,17 +390,8 @@
|
||||
block-id (when (map? properties) (get properties :id))
|
||||
content (-> (property/remove-built-in-properties format content)
|
||||
(drawer/remove-logbook))]
|
||||
(cond
|
||||
(another-block-with-same-id-exists? uuid block-id)
|
||||
(notification/show!
|
||||
[:p.content
|
||||
(util/format "Block with the id %s already exists!" block-id)]
|
||||
:error)
|
||||
|
||||
force?
|
||||
(if force?
|
||||
(save-block-inner! block value opts)
|
||||
|
||||
:else
|
||||
(let [content-changed? (not= (string/trim content) (string/trim value))]
|
||||
(when (and content-changed? page)
|
||||
(save-block-inner! block value opts)))))))
|
||||
@@ -778,10 +769,13 @@
|
||||
(gobj/get (utf8/encode original-content) "length")
|
||||
0)
|
||||
0)
|
||||
f (fn [] (edit-block! block pos id
|
||||
{:custom-content new-value
|
||||
:tail-len tail-len
|
||||
:move-cursor? false}))]
|
||||
f (fn []
|
||||
(prn {:pos pos})
|
||||
(edit-block! (db/pull (:db/id block))
|
||||
pos
|
||||
id
|
||||
{:custom-content new-value
|
||||
:tail-len tail-len}))]
|
||||
(when move? (f))
|
||||
{:prev-block block
|
||||
:new-content new-value
|
||||
|
||||
@@ -38,9 +38,8 @@
|
||||
(defn edit-block!
|
||||
([block pos id]
|
||||
(edit-block! block pos id nil))
|
||||
([block pos id {:keys [custom-content tail-len move-cursor? retry-times]
|
||||
([block pos id {:keys [custom-content tail-len retry-times]
|
||||
:or {tail-len 0
|
||||
move-cursor? true
|
||||
retry-times 0}
|
||||
:as opts}]
|
||||
(when-not (> retry-times 2)
|
||||
@@ -70,7 +69,7 @@
|
||||
(drawer/remove-logbook))]
|
||||
(clear-selection!)
|
||||
(if edit-input-id
|
||||
(state/set-editing! edit-input-id content block text-range move-cursor?)
|
||||
(state/set-editing! edit-input-id content block text-range)
|
||||
;; Block may not be rendered yet
|
||||
(js/setTimeout (fn [] (edit-block! block pos id (update opts :retry-times inc))) 10))))))))
|
||||
|
||||
@@ -138,4 +137,4 @@
|
||||
(defn set-block-property!
|
||||
[block-id key value]
|
||||
(let [key (keyword key)]
|
||||
(batch-set-block-property! [[block-id key value]])))
|
||||
(batch-set-block-property! [[block-id key value]])))
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
[frontend.config :as config]
|
||||
[logseq.graph-parser.util :as gp-util]
|
||||
[lambdaisland.glogi :as log]
|
||||
[frontend.search :as search])))
|
||||
[frontend.search :as search]
|
||||
[clojure.string :as string])))
|
||||
|
||||
#?(:cljs
|
||||
(defn new-outliner-txs-state [] (atom [])))
|
||||
@@ -56,22 +57,27 @@
|
||||
(defn update-block-refs
|
||||
[txs opts]
|
||||
(if-let [changed (:uuid-changed opts)]
|
||||
(let [{:keys [from to]} changed
|
||||
from-e (db/entity [:block/uuid from])
|
||||
to-e (db/entity [:block/uuid to])
|
||||
from-id (:db/id from-e)
|
||||
to-id (:db/id to-e)
|
||||
refs (:block/_refs from-e)
|
||||
path-refs (:block/_path-refs from-e)
|
||||
refs-txs (mapcat (fn [ref refs]
|
||||
(let [id (:db/id ref)]
|
||||
[[:db/retract id :block/refs from-id]
|
||||
[:db/add id :block/refs to-id]])) refs)
|
||||
path-refs-txs (mapcat (fn [ref refs]
|
||||
(let [{:keys [kept deleted]} changed
|
||||
kept-e (db/entity [:block/uuid kept])
|
||||
deleted-e (db/entity [:block/uuid deleted])
|
||||
kept-id (:db/id kept-e)
|
||||
deleted-id (:db/id deleted-e)
|
||||
kept-refs (:block/_refs kept-e)
|
||||
kept-path-refs (:block/_path-refs kept-e)
|
||||
deleted-refs (:block/_refs deleted-e)
|
||||
kept-refs-txs (mapcat (fn [ref refs]
|
||||
(let [id (:db/id ref)]
|
||||
[[:db/retract id :block/path-refs from-id]
|
||||
[:db/add id :block/path-refs to-id]])) path-refs)]
|
||||
(concat txs refs-txs path-refs-txs))
|
||||
[[:db/retract id :block/refs kept-id]
|
||||
[:db/add id :block/refs deleted-id]])) kept-refs)
|
||||
kept-path-refs-txs (mapcat (fn [ref refs]
|
||||
(let [id (:db/id ref)]
|
||||
[[:db/retract id :block/path-refs kept-id]
|
||||
[:db/add id :block/path-refs deleted-id]])) kept-path-refs)
|
||||
deleted-refs-txs (mapcat (fn [ref refs]
|
||||
(let [id (:db/id ref)]
|
||||
(let [new-content (string/replace (:block/content ref) (str deleted) (str kept))]
|
||||
[[:db/add id :block/content new-content]]))) deleted-refs)]
|
||||
(concat txs kept-refs-txs kept-path-refs-txs deleted-refs-txs))
|
||||
txs)))
|
||||
|
||||
#?(:cljs
|
||||
@@ -94,8 +100,8 @@
|
||||
(not (contains? (:file/unlinked-dirs @state/state)
|
||||
(config/get-repo-dir repo)))))
|
||||
|
||||
;; (prn "[DEBUG] Outliner transact:")
|
||||
;; (frontend.util/pprint txs)
|
||||
(prn "[DEBUG] Outliner transact:")
|
||||
(frontend.util/pprint txs)
|
||||
|
||||
(try
|
||||
(let [repo (get opts :repo (state/get-current-repo))
|
||||
|
||||
Reference in New Issue
Block a user