|
|
@@ -7,32 +7,35 @@
|
|
|
[frontend.state :as state]
|
|
|
[frontend.util.cursor :as cursor]
|
|
|
[frontend.util.drawer :as drawer]
|
|
|
- [frontend.modules.editor.undo-redo :as undo-redo]))
|
|
|
+ [frontend.modules.editor.undo-redo :as undo-redo]
|
|
|
+ [datascript.core :as d]))
|
|
|
|
|
|
(defn- reset-editing-block-content!
|
|
|
[tx-data tx-meta]
|
|
|
- (let [repo (state/get-current-repo)
|
|
|
- db? (config/db-based-graph? repo)]
|
|
|
- (when-not (or (:undo? tx-meta) (:redo? tx-meta))
|
|
|
- (when-let [edit-block (state/get-edit-block)]
|
|
|
- (when-let [last-datom (-> (filter (fn [datom]
|
|
|
- (and (= :block/content (:a datom))
|
|
|
- (= (:e datom) (:db/id edit-block)))) tx-data)
|
|
|
- last)]
|
|
|
- (when-let [input (state/get-input)]
|
|
|
- (when (:added last-datom)
|
|
|
- (let [entity (db/entity (:e last-datom))
|
|
|
- db-content (:block/content entity)
|
|
|
- content (if db? db-content
|
|
|
- (->> db-content
|
|
|
- (property-util/remove-built-in-properties (or (:block/format entity) :markdown))
|
|
|
- drawer/remove-logbook))
|
|
|
- pos (cursor/pos input)
|
|
|
- pos (when pos (if (zero? pos) (count content) 0))]
|
|
|
- (when (not= (string/trim content)
|
|
|
- (string/trim (.-value input)))
|
|
|
- (state/set-edit-content! input content))
|
|
|
- (when pos (cursor/move-cursor-to input pos))))))))))
|
|
|
+ ;; FIXME:
|
|
|
+ ;; (let [repo (state/get-current-repo)
|
|
|
+ ;; db? (config/db-based-graph? repo)]
|
|
|
+ ;; (when-not (or (:undo? tx-meta) (:redo? tx-meta))
|
|
|
+ ;; (when-let [edit-block (state/get-edit-block)]
|
|
|
+ ;; (when-let [last-datom (-> (filter (fn [datom]
|
|
|
+ ;; (and (= :block/content (:a datom))
|
|
|
+ ;; (= (:e datom) (:db/id edit-block)))) tx-data)
|
|
|
+ ;; last)]
|
|
|
+ ;; (when-let [input (state/get-input)]
|
|
|
+ ;; (when (:added last-datom)
|
|
|
+ ;; (let [entity (db/entity (:e last-datom))
|
|
|
+ ;; db-content (:block/content entity)
|
|
|
+ ;; content (if db? db-content
|
|
|
+ ;; (->> db-content
|
|
|
+ ;; (property-util/remove-built-in-properties (or (:block/format entity) :markdown))
|
|
|
+ ;; drawer/remove-logbook))
|
|
|
+ ;; pos (cursor/pos input)
|
|
|
+ ;; pos (when pos (if (zero? pos) (count content) 0))]
|
|
|
+ ;; (when (not= (string/trim content)
|
|
|
+ ;; (string/trim (.-value input)))
|
|
|
+ ;; (state/set-edit-content! input content))
|
|
|
+ ;; (when pos (cursor/move-cursor-to input pos)))))))))
|
|
|
+ )
|
|
|
|
|
|
(defn store-undo-data!
|
|
|
[{:keys [tx-meta] :as opts}]
|
|
|
@@ -47,12 +50,16 @@
|
|
|
|
|
|
(defn invoke-hooks
|
|
|
[{:keys [tx-meta tx-data deleted-block-uuids affected-keys blocks] :as opts}]
|
|
|
- (store-undo-data! opts)
|
|
|
- (let [{:keys [from-disk? new-graph?]} tx-meta
|
|
|
+ (let [{:keys [from-disk? new-graph? local-tx?]} tx-meta
|
|
|
repo (state/get-current-repo)
|
|
|
tx-report {:tx-meta tx-meta
|
|
|
:tx-data tx-data}]
|
|
|
|
|
|
+ (when local-tx? (store-undo-data! opts))
|
|
|
+
|
|
|
+ (let [conn (db/get-db repo false)]
|
|
|
+ (d/transact! conn tx-data tx-meta))
|
|
|
+
|
|
|
(when (= (:outliner-op tx-meta) :delete-page)
|
|
|
(state/pub-event! [:page/deleted repo (:deleted-page tx-meta) (:file-path tx-meta)]))
|
|
|
|
|
|
@@ -65,6 +72,7 @@
|
|
|
(catch :default e
|
|
|
(prn :reset-editing-block-content)
|
|
|
(js/console.error e)))
|
|
|
+
|
|
|
(let [importing? (:graph/importing @state/state)]
|
|
|
(when-not importing?
|
|
|
(react/refresh! repo tx-report affected-keys))
|