enhance: disable patches for undo/redo temporally

pull/1302/head
Tienson Qin 2021-02-10 08:03:15 +08:00
parent 8b41cbadc3
commit fb15b4beab
1 changed files with 10 additions and 14 deletions

View File

@ -21,7 +21,7 @@
;; repo -> idx
(defonce history-idx (atom {}))
(defonce history-limit 500)
(defonce history-limit 100)
;; tx [[file1-path patches] [file2-path patches]]
(defn add-history!
@ -30,9 +30,8 @@
(remove (fn [[_ old new]] (= old new)))
(map (fn [[file old new]]
(when (and old new)
(let [diffs (diff/diffs new old)
patches (diff/get-patches new old diffs)]
[file patches {:old old
(let [diffs (diff/diffs new old)]
[file {:old old
:new new}]))))
(remove nil?))]
(when (seq tx)
@ -74,10 +73,9 @@
tx (get-in @history [repo idx'])
{:keys [data]} tx
_ (reset! *undoing? true)
promises (for [[path patches] data]
(let [current-content (db/get-file-no-sub path)
original-content (diff/apply-patches! current-content patches)]
(alter-file repo path original-content
promises (for [[path {:keys [old]}] data]
(let [current-content (db/get-file-no-sub path)]
(alter-file repo path old
{:add-history? false
:re-render-root? true})))]
(-> (p/all promises)
@ -98,11 +96,9 @@
(when (and (> (count txs) idx) (false? @*redoing?))
(let [tx (get-in @history [repo idx])
_ (reset! *redoing? true)
promises (for [[path patches] (:data tx)]
(let [current-content (db/get-file-no-sub path)
reversed-patches (utils/reversePatch patches)
content (diff/apply-patches! current-content reversed-patches)]
(alter-file repo path content
promises (for [[path {:keys [new]}] (:data tx)]
(let [current-content (db/get-file-no-sub path)]
(alter-file repo path new
{:add-history? false
:re-render-root? true})))]
(-> (p/all promises)