fix: lint

This commit is contained in:
Tienson Qin
2026-03-23 18:00:50 +08:00
parent ae3c9092d2
commit bfa64bd922
4 changed files with 35 additions and 67 deletions

View File

@@ -1,8 +1,7 @@
(ns frontend.undo-redo
"Main-thread proxy for worker-owned undo/redo."
(:require [frontend.state :as state]
[frontend.util :as util]
[frontend.worker.undo-redo :as worker-undo-redo]))
[frontend.util :as util]))
(defn- worker-not-initialized?
[e]
@@ -19,82 +18,52 @@
result))
(defn- invoke-db-worker
[thread-api & args]
(try
(apply state/<invoke-db-worker thread-api args)
(catch :default e
(if (worker-not-initialized? e)
nil
(throw e)))))
(defn clear-history!
[repo]
(if util/node-test?
(do
(worker-undo-redo/clear-history! repo)
nil)
(try
(state/<invoke-db-worker :thread-api/undo-redo-clear-history repo)
(catch :default e
(if (worker-not-initialized? e)
(do
(worker-undo-redo/clear-history! repo)
nil)
(throw e))))))
nil
(invoke-db-worker :thread-api/undo-redo-clear-history repo)))
(defn undo
[repo]
(if util/node-test?
(normalize-empty-result (worker-undo-redo/undo repo))
(try
(state/<invoke-db-worker :thread-api/undo-redo-undo repo)
(catch :default e
(if (worker-not-initialized? e)
(normalize-empty-result (worker-undo-redo/undo repo))
(throw e))))))
:frontend.undo-redo/empty-undo-stack
(or (some-> (invoke-db-worker :thread-api/undo-redo-undo repo)
normalize-empty-result)
:frontend.undo-redo/empty-undo-stack)))
(defn redo
[repo]
(if util/node-test?
(normalize-empty-result (worker-undo-redo/redo repo))
(try
(state/<invoke-db-worker :thread-api/undo-redo-redo repo)
(catch :default e
(if (worker-not-initialized? e)
(normalize-empty-result (worker-undo-redo/redo repo))
(throw e))))))
:frontend.undo-redo/empty-redo-stack
(or (some-> (invoke-db-worker :thread-api/undo-redo-redo repo)
normalize-empty-result)
:frontend.undo-redo/empty-redo-stack)))
(defn record-editor-info!
[repo editor-info]
(when editor-info
(if util/node-test?
(do
(worker-undo-redo/record-editor-info! repo editor-info)
nil)
(try
(state/<invoke-db-worker :thread-api/undo-redo-record-editor-info repo editor-info)
(catch :default e
(if (worker-not-initialized? e)
(do
(worker-undo-redo/record-editor-info! repo editor-info)
nil)
(throw e)))))))
nil
(invoke-db-worker :thread-api/undo-redo-record-editor-info repo editor-info))))
(defn record-ui-state!
[repo ui-state-str]
(when ui-state-str
(if util/node-test?
(do
(worker-undo-redo/record-ui-state! repo ui-state-str)
nil)
(try
(state/<invoke-db-worker :thread-api/undo-redo-record-ui-state repo ui-state-str)
(catch :default e
(if (worker-not-initialized? e)
(do
(worker-undo-redo/record-ui-state! repo ui-state-str)
nil)
(throw e)))))))
nil
(invoke-db-worker :thread-api/undo-redo-record-ui-state repo ui-state-str))))
(defn <get-debug-state
[repo]
(if util/node-test?
(worker-undo-redo/get-debug-state repo)
(try
(state/<invoke-db-worker :thread-api/undo-redo-get-debug-state repo)
(catch :default e
(if (worker-not-initialized? e)
(worker-undo-redo/get-debug-state repo)
(throw e))))))
(when-not util/node-test?
(invoke-db-worker :thread-api/undo-redo-get-debug-state repo)))

View File

@@ -314,7 +314,7 @@
:reason :invalid-history-action-tx
:error error})))
(defn apply-history-action!
(defn ^:large-vars/cleanup-todo apply-history-action!
[repo tx-id undo? tx-meta]
(let [debug-data {:tx-id tx-id
:undo? undo?

View File

@@ -1972,7 +1972,7 @@
steps
(recur (inc steps))))))
(deftest ^:long all-core-outliner-ops-local-undo-redo-random-sim-test
(deftest ^:long ^:large-vars/cleanup-todo all-core-outliner-ops-local-undo-redo-random-sim-test
(testing "local randomized stress simulation runs weighted ops and keeps undo-all/redo-all roundtrips valid"
(let [seed (or (env-seed) default-seed)
rng (make-rng seed)
@@ -2046,25 +2046,25 @@
(str "failed to prepare undo stack seed=" seed))
(let [max-stack-steps (+ (* 2 local-undo-redo-run-count) 5000)]
(dotimes [cycle local-undo-redo-full-cycle-runs]
(dotimes [cycle-idx local-undo-redo-full-cycle-runs]
(let [undo-steps (undo-all! repo-a max-stack-steps)
issues-after-undo (db-issues @conn)]
(is (pos? undo-steps)
(str "expected undo steps cycle=" cycle " seed=" seed))
(str "expected undo steps cycle=" cycle-idx " seed=" seed))
(is (empty? issues-after-undo)
(str "db issues after undo-all cycle=" cycle " seed=" seed
(str "db issues after undo-all cycle=" cycle-idx " seed=" seed
" " (pr-str issues-after-undo)))
(assert-no-invalid-tx! seed history repro)
(let [redo-steps (redo-all! repo-a max-stack-steps)
issues-after-redo (db-issues @conn)
attrs-after-redo (block-attr-map @conn)]
(is (pos? redo-steps)
(str "expected redo steps cycle=" cycle " seed=" seed))
(str "expected redo steps cycle=" cycle-idx " seed=" seed))
(is (empty? issues-after-redo)
(str "db issues after redo-all cycle=" cycle " seed=" seed
(str "db issues after redo-all cycle=" cycle-idx " seed=" seed
" " (pr-str issues-after-redo)))
(is (seq attrs-after-redo)
(str "db should not be empty after redo-all cycle=" cycle
(str "db should not be empty after redo-all cycle=" cycle-idx
" seed=" seed))
(assert-no-invalid-tx! seed history repro)))))