浏览代码

fix: undo cursor

Tienson Qin 4 年之前
父节点
当前提交
d1359c3418

+ 0 - 1
src/main/frontend/handler/editor.cljs

@@ -458,7 +458,6 @@
                      (dissoc :db/id :block/collapsed?)
                      (wrap-parse-block))]
     (do
-      (repo-handler/update-last-edit-block)
       (profile
        "outliner insert block"
        (outliner-insert-block! current-block next-block block-self?))

+ 2 - 0
src/main/frontend/handler/editor/lifecycle.cljs

@@ -8,6 +8,7 @@
             [cljs-drag-n-drop.core :as dnd]
             [frontend.handler.editor.keyboards :as keyboards-handler]
             [frontend.handler.page :as page-handler]
+            [frontend.handler.repo :as repo-handler]
             [frontend.handler.editor :as editor-handler :refer [get-state]]
             [frontend.handler.notification :as notification]
             [frontend.db :as db]
@@ -18,6 +19,7 @@
 
 (defn did-mount!
   [state]
+  (repo-handler/update-last-edit-block)
   (let [[{:keys [dummy? format block-parent-id]} id] (:rum/args state)
         content (get-in @state/state [:editor/content id])
         input (gdom/getElement id)]

+ 2 - 1
src/main/frontend/handler/history.cljs

@@ -30,7 +30,8 @@
         (when-let [block (db/pull [:block/uuid block-uuid])]
           (editor/edit-block! block pos
                               (:block/format block)
-                              (:block/uuid block)))))))
+                              (:block/uuid block)
+                              {:custom-content (:block/content block)}))))))
 
 (defn undo!
   []

+ 5 - 1
src/main/frontend/state.cljs

@@ -674,6 +674,7 @@
                          :block/container (gobj/get container "id"))
                   block)
           content (or content "")]
+
       (swap! state
              (fn [state]
                (-> state
@@ -682,7 +683,10 @@
                     :editor/block block
                     :editor/editing? {edit-input-id true}
                     :editor/last-edit-block-id edit-input-id
-                    :cursor-range cursor-range)))))))
+                    :cursor-range cursor-range))))
+
+      (let [input (gdom/getElement edit-input-id)]
+        (set! (.-value input) (string/trim content))))))
 
 (defn clear-edit!
   []