fix: auto save on editing properties

This commit is contained in:
Junyi Du
2022-03-24 14:46:00 +08:00
parent 5a24d63f54
commit cf430963af
3 changed files with 21 additions and 10 deletions

View File

@@ -1270,7 +1270,7 @@
(defn save-current-block!
([]
(save-current-block! {}))
([{:keys [force?] :as opts}]
([{:keys [force? skip-properties?] :as opts}]
;; non English input method
(when-not (state/editor-in-composition?)
(when (state/get-current-repo)
@@ -1296,6 +1296,11 @@
force?
(save-block-aux! db-block value opts)
(and skip-properties?
(db-model/top-block? block)
(when elem (thingatpt/properties-at-point elem)))
nil
(and block value db-content-without-heading
(not= (string/trim db-content-without-heading)
(string/trim value)))
@@ -1801,17 +1806,14 @@
(when @*auto-save-timeout
(js/clearTimeout @*auto-save-timeout))
(mark-last-input-time! repo)
(when-not
(and
(= (:db/id (:block/parent block))
(:db/id (:block/page block))) ; don't auto-save for page's properties block
(get-in block [:block/properties :title]))
(when-not (and (db-model/top-block? block) ; don't auto-save for page's properties block
(not-empty (:block/properties block)))
(reset! *auto-save-timeout
(js/setTimeout
(fn []
(when (state/input-idle? repo)
(state/set-editor-op! :auto-save)
(save-current-block! {})
(save-current-block! {:skip-properties? true})
(state/set-editor-op! nil)))
500)))))