Przeglądaj źródła

fix: blockrefs e2e tests

Tienson Qin 2 lat temu
rodzic
commit
f5cee63716

+ 10 - 4
src/main/frontend/handler/editor.cljs

@@ -745,7 +745,8 @@
                          {:custom-content new-value
                           :tail-len tail-len})
             {:prev-block block
-             :new-content new-value}))))))
+             :new-content new-value
+             :pos pos}))))))
 
 (declare save-block!)
 
@@ -777,7 +778,7 @@
                                     block-parent
                                     {:container (util/rec-get-blocks-container block-parent)})
                                    (util/get-prev-block-non-collapsed-non-embed block-parent))
-                   {:keys [prev-block new-content]} (move-to-prev-block repo sibling-block format id value)
+                   {:keys [prev-block new-content pos]} (move-to-prev-block repo sibling-block format id value)
                    concat-prev-block? (boolean (and prev-block new-content))
                    transact-opts (cond->
                                   {:outliner-op :delete-blocks}
@@ -801,7 +802,12 @@
                                                   :block/uuid (:block/uuid block)
                                                   :block/parent (:db/id (:block/parent prev-block))
                                                   :block/left (or (:db/id (:block/left prev-block))
-                                                                  (:db/id (:block/parent prev-block)))}))
+                                                                  (:db/id (:block/parent prev-block)))})
+                      (when pos
+                        (util/schedule
+                         (fn []
+                           (when-let [input (state/get-input)]
+                             (cursor/move-cursor-to input pos))))))
                     (do
                       (delete-block-aux! block delete-children?)
                       (save-block! repo prev-block new-content {:editor/op :delete})))
@@ -2685,7 +2691,7 @@
           :concat-data {:last-edit-block (:block/uuid edit-block)
                         :end? true}}
          (delete-block-aux! next-block false)
-         (save-block! repo edit-block' new-content {:editor/op :delete}))
+          (save-block! repo edit-block' new-content {:editor/op :delete}))
         (let [block (if next-block-has-refs? next-block edit-block)]
           (edit-block! block current-pos nil))))))
 

+ 32 - 24
src/main/frontend/modules/outliner/pipeline.cljs

@@ -10,7 +10,10 @@
             [promesa.core :as p]
             [frontend.persist-db :as persist-db]
             [clojure.string :as string]
-            [datascript.core :as d]))
+            [datascript.core :as d]
+            [frontend.handler.file-based.property.util :as property-util]
+            [frontend.util.drawer :as drawer]
+            [frontend.util.cursor :as cursor]))
 
 (defn updated-page-hook
   [tx-report page]
@@ -26,19 +29,26 @@
 
 (defn- reset-editing-block-content!
   [tx-data]
-  (let [repo (state/get-current-repo)]
-    (when (config/db-based-graph? repo)
-      (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 [db-content (:block/content (db/entity (:e last-datom)))]
-                (when (not= (string/trim db-content)
-                            (string/trim (.-value input)))
-                  (state/set-edit-content! input db-content))))))))))
+  (let [repo (state/get-current-repo)
+        db? (config/db-based-graph? repo)]
+    (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)]
+              (when (not= (string/trim content)
+                          (string/trim (.-value input)))
+                (state/set-edit-content! input content)
+                (when pos (cursor/move-cursor-to input pos))))))))))
 
 (defn- delete-property-parent-block-if-empty!
   [repo tx-report deleted-block-uuids]
@@ -94,7 +104,7 @@
         (when-not importing?
           (react/refresh! repo tx-report'))
 
-        (when (and (config/db-based-graph? repo) (not (:skip-persist? tx-meta))
+        (when (and (not (:skip-persist? tx-meta))
                    (not replace?)
                    (not (:update-tx-ids? tx-meta)))
           (let [upsert-blocks (outliner-pipeline/build-upsert-blocks blocks deleted-block-uuids (:db-after tx-report'))
@@ -107,15 +117,13 @@
             (when (seq update-tx-ids)
               (db/transact! repo update-tx-ids {:replace? true
                                                 :update-tx-ids? true}))
-            (when-not config/publishing?
-              (p/let [_transact-result (persist-db/<transact-data repo upsert-blocks deleted-block-uuids)
-                      _ipc-result (comment ipc/ipc :db-transact-data repo
-                                           (pr-str
-                                            {:blocks upsert-blocks
-                                             :deleted-block-uuids deleted-block-uuids}))]
-              ;; TODO: disable edit when transact failed to avoid future data-loss
-              ;; (prn "DB transact result: " ipc-result)
-                ))))
+            (when (config/db-based-graph? repo)
+              (when-not config/publishing?
+                (p/let [_transact-result (persist-db/<transact-data repo upsert-blocks deleted-block-uuids)
+                        _ipc-result (comment ipc/ipc :db-transact-data repo
+                                             (pr-str
+                                              {:blocks upsert-blocks
+                                               :deleted-block-uuids deleted-block-uuids}))])))))
 
         (when (and (not (:delete-files? tx-meta))
                    (not replace?))