mirror of https://github.com/logseq/logseq
fix: undo/redo paginations
parent
d40c0d8926
commit
b7025b9ce4
|
@ -699,14 +699,12 @@
|
|||
current-db (conn/get-db repo-url)]
|
||||
(cond
|
||||
(and (or (:undo? tx-meta) (:redo? tx-meta)) @result)
|
||||
(when-let [start-id (get-start-id-for-pagination-query
|
||||
repo-url current-db tx-report result outliner-op page-id block-id tx-block-ids)]
|
||||
(let [end-block-id (:db/id (:end (meta @result)))
|
||||
previous-blocks (take-while (fn [b] (not= start-id (:db/id b))) @result)
|
||||
more (get-paginated-blocks-no-cache current-db start-id {:end-id end-block-id
|
||||
:include-start? true
|
||||
:scoped-block-id scoped-block-id})]
|
||||
(concat previous-blocks more)))
|
||||
(let [blocks-range (:pagination-blocks-range tx-meta)
|
||||
[start-block-id end-block-id] (:new blocks-range)]
|
||||
(get-paginated-blocks-no-cache current-db start-block-id
|
||||
{:end-id end-block-id
|
||||
:include-start? true
|
||||
:scoped-block-id scoped-block-id}))
|
||||
|
||||
(contains? #{:save-block :delete-blocks} outliner-op)
|
||||
@result
|
||||
|
|
|
@ -70,26 +70,27 @@
|
|||
;; component -> query-key
|
||||
(defonce query-components (atom {}))
|
||||
|
||||
(defn- with-block-start-end
|
||||
(defn- get-blocks-range
|
||||
[result-atom new-result]
|
||||
(let [block? (and (coll? @result-atom) (map? (first @result-atom)) (:block/uuid (first @result-atom)))
|
||||
[start end] (when block?
|
||||
[(first @result-atom)
|
||||
(last @result-atom)])
|
||||
new-result (if block? (util/distinct-by-last-wins :block/uuid new-result) new-result)]
|
||||
(with-meta new-result {:start (select-keys start [:db/id :block/uuid :block/content])
|
||||
:end (select-keys end [:db/id :block/uuid :block/content])})))
|
||||
(let [block? (and (coll? @result-atom) (map? (first @result-atom)) (:block/uuid (first @result-atom)))]
|
||||
(when block?
|
||||
{:old [(:db/id (first @result-atom))
|
||||
(:db/id (last @result-atom))]
|
||||
:new [(:db/id (first new-result))
|
||||
(:db/id (last new-result))]})))
|
||||
|
||||
(defn set-new-result!
|
||||
[k new-result]
|
||||
[k new-result tx-report]
|
||||
(when-let [result-atom (get-in @query-state [k :result])]
|
||||
(let [new-result' (with-block-start-end result-atom new-result)]
|
||||
(reset! result-atom new-result'))))
|
||||
(when tx-report
|
||||
(when-let [range (get-blocks-range result-atom new-result)]
|
||||
(state/set-state! [:ui/pagination-blocks-range (get-in tx-report [:db-after :max-tx])] range)))
|
||||
(reset! result-atom new-result)))
|
||||
|
||||
(defn swap-new-result!
|
||||
[k f]
|
||||
(when-let [result-atom (get-in @query-state [k :result])]
|
||||
(let [new-result' (with-block-start-end result-atom (f @result-atom))]
|
||||
(let [new-result' (f @result-atom)]
|
||||
(reset! result-atom new-result'))))
|
||||
|
||||
(defn kv
|
||||
|
@ -101,7 +102,7 @@
|
|||
(defn remove-key!
|
||||
[repo-url key]
|
||||
(db-utils/transact! repo-url [[:db.fn/retractEntity [:db/ident key]]])
|
||||
(set-new-result! [repo-url :kv key] nil))
|
||||
(set-new-result! [repo-url :kv key] nil nil))
|
||||
|
||||
(defn clear-query-state!
|
||||
[]
|
||||
|
@ -294,7 +295,7 @@
|
|||
(d/q query db))
|
||||
transform-fn)]
|
||||
(when-not (= new-result result)
|
||||
(set-new-result! k new-result))))
|
||||
(set-new-result! k new-result (:tx-report tx)))))
|
||||
|
||||
(defn refresh!
|
||||
"Re-compute corresponding queries (from tx) and refresh the related react components."
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
(ns frontend.handler.history
|
||||
(:require [frontend.db :as db]
|
||||
[frontend.handler.editor :as editor]
|
||||
[frontend.handler.ui :as ui-handler]
|
||||
[frontend.modules.editor.undo-redo :as undo-redo]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
|
@ -9,7 +8,6 @@
|
|||
|
||||
(defn restore-cursor!
|
||||
[{:keys [last-edit-block container pos]}]
|
||||
;; (ui-handler/re-render-root!)
|
||||
(when (and container last-edit-block)
|
||||
#_:clj-kondo/ignore
|
||||
(when-let [container (gdom/getElement container)]
|
||||
|
|
|
@ -106,7 +106,8 @@
|
|||
(:editor-cursor prev-e)
|
||||
(:editor-cursor e))]
|
||||
(push-redo e)
|
||||
(transact! new-txs {:undo? true})
|
||||
(transact! new-txs (merge {:undo? true}
|
||||
(select-keys e [:pagination-blocks-range])))
|
||||
(assoc e
|
||||
:txs-op new-txs
|
||||
:editor-cursor editor-cursor)))))
|
||||
|
@ -116,7 +117,8 @@
|
|||
(when-let [{:keys [txs]:as e} (pop-redo)]
|
||||
(let [new-txs (get-txs true txs)]
|
||||
(push-undo e)
|
||||
(transact! new-txs {:redo? true})
|
||||
(transact! new-txs (merge {:redo? true}
|
||||
(select-keys e [:pagination-blocks-range])))
|
||||
(assoc e :txs-op new-txs))))
|
||||
|
||||
(defn listen-outliner-operation
|
||||
|
@ -124,6 +126,8 @@
|
|||
(when-not (empty? tx-data)
|
||||
(reset-redo)
|
||||
(let [updated-blocks (db-report/get-blocks tx-report)
|
||||
entity {:blocks updated-blocks :txs tx-data
|
||||
:editor-cursor (:editor-cursor tx-meta)}]
|
||||
entity {:blocks updated-blocks
|
||||
:txs tx-data
|
||||
:editor-cursor (:editor-cursor tx-meta)
|
||||
:pagination-blocks-range (get-in [:ui/pagination-blocks-range (get-in tx-report [:db-after :max-tx])] @state/state)}]
|
||||
(push-undo entity))))
|
||||
|
|
Loading…
Reference in New Issue