Browse Source

fix: open block for editing after pressing Enter in a text property

Tienson Qin 1 year ago
parent
commit
c8a7a4e627

+ 8 - 6
src/main/frontend/components/property/value.cljs

@@ -312,12 +312,14 @@
 
 (defn <create-new-block!
   [block property value]
-  (p/let [last-block-id (db-property-handler/create-property-text-block! block property value
-                                                                       editor-handler/wrap-parse-block
-
-                                                                       {})
-          _ (exit-edit-property)]
-    (editor-handler/edit-block! (db/entity [:block/uuid last-block-id]) :max last-block-id)))
+  (let [{:keys [last-block-id result]} (db-property-handler/create-property-text-block! block property value
+                                                                                        editor-handler/wrap-parse-block
+
+                                                                                        {})]
+    (p/do!
+     result
+     (exit-edit-property)
+     (editor-handler/edit-block! (db/entity [:block/uuid last-block-id]) :max last-block-id))))
 
 (defn <create-new-block-from-template!
   "`template`: tag block"

+ 6 - 5
src/main/frontend/handler/db_based/property.cljs

@@ -617,11 +617,12 @@
         class? (contains? (:block/type block) "class")
         property-key (:block/original-name property)]
     (db/transact! repo (if page (cons page blocks) blocks) {:outliner-op :insert-blocks})
-    (when property-key
-      (if (and class? class-schema?)
-        (class-add-property! repo (:block/uuid block) property-key)
-        (set-block-property! repo (:block/uuid block) property-key (:block/uuid first-block) {})))
-    last-block-id))
+    (let [result (when property-key
+                   (if (and class? class-schema?)
+                     (class-add-property! repo (:block/uuid block) property-key)
+                     (set-block-property! repo (:block/uuid block) property-key (:block/uuid first-block) {})))]
+      {:last-block-id last-block-id
+       :result result})))
 
 (defn property-create-new-block-from-template
   [block property template]

+ 1 - 1
src/test/frontend/handler/db_based/property_test.cljs

@@ -291,7 +291,7 @@
       ;; add property
       (db-property-handler/upsert-property! repo k {:type :default} {})
       (let [property (db/entity [:block/name k])
-            last-block-id (db-property-handler/create-property-text-block! fb property "Block content" editor-handler/wrap-parse-block {})
+            {:keys [last-block-id]} (db-property-handler/create-property-text-block! fb property "Block content" editor-handler/wrap-parse-block {})
             {:keys [from-block-id from-property-id]} (db-property-handler/get-property-block-created-block [:block/uuid last-block-id])]
         (is (= from-block-id (:db/id fb)))
         (is (= from-property-id (:db/id property)))))))