ソースを参照

fix: save block when editor unmounts is dangerous

The block content will be overwritten in those cases:
1. deleting a block
2. paste blocks to an empty target block
3. undo/redo
Tienson Qin 1 年間 前
コミット
b1d4fb3b81

+ 3 - 1
src/main/frontend/commands.cljs

@@ -816,7 +816,9 @@
     (.click input-file)))
 
 (defmethod handle-step :editor/exit [[_]]
-  (state/clear-edit!))
+  (p/do!
+    (state/pub-event! [:editor/save-current-block])
+    (state/clear-edit!)))
 
 (defmethod handle-step :editor/new-property [[_]]
   (state/pub-event! [:editor/new-property]))

+ 1 - 6
src/main/frontend/components/editor.cljs

@@ -854,12 +854,7 @@
                   ::ref (atom nil)))
    :did-mount (fn [state]
                 (state/set-editor-args! (:rum/args state))
-                state)
-   :will-unmount (fn [state]
-                   (let [{:keys [block value]} (editor-handler/get-state)]
-                     (when-not (= (:block/uuid block) (:editor/deleting-block @state/state)) ; don't save deleting block
-                       (editor-handler/save-block! (state/get-current-repo) (:block/uuid block) value)))
-                   state)}
+                state)}
   (mixins/event-mixin
    (fn [state]
      (mixins/hide-when-esc-or-outside