Browse Source

try to fix scroll position when switch editing mode (#867)

Charlie 5 years ago
parent
commit
90093e4d12
2 changed files with 19 additions and 17 deletions
  1. 2 2
      src/main/frontend/components/editor.cljs
  2. 17 15
      src/main/frontend/state.cljs

+ 2 - 2
src/main/frontend/components/editor.cljs

@@ -696,7 +696,7 @@
        :on-change (fn [e]
                     (let [value (util/evalue e)
                           current-pos (:pos (util/get-caret-pos (gdom/getElement id)))]
-                      (state/set-edit-content! id value)
+                      (state/set-edit-content! id value false)
                       (state/set-edit-pos! current-pos)
                       (when-let [repo (or (:block/repo block)
                                           (state/get-current-repo))]
@@ -717,7 +717,7 @@
                             (reset! *angle-bracket-caret-pos (util/get-caret-pos input))
                             (reset! *show-block-commands true))
                           nil))))
-       :auto-focus true})
+       :auto-focus false})
 
      ;; TODO: how to render the transitions asynchronously?
      (transition-cp

+ 17 - 15
src/main/frontend/state.cljs

@@ -311,21 +311,23 @@
   (:editor/set-timestamp-block @state))
 
 (defn set-edit-content!
-  [input-id value]
-  (when input-id
-    (when-let [input (gdom/getElement input-id)]
-      (util/set-change-value input value))
-    (update-state! :editor/content (fn [m]
-                                     (assoc m input-id value)))
-    ;; followers
-    ;; (when-let [s (util/extract-uuid input-id)]
-    ;;   (let [input (gdom/getElement input-id)
-    ;;         leader-parent (util/rec-get-block-node input)
-    ;;         followers (->> (array-seq (js/document.getElementsByClassName s))
-    ;;                        (remove #(= leader-parent %)))]
-    ;;     (prn "followers: " (count followers))
-    ;;     ))
-))
+  ([input-id value] (set-edit-content! input-id value true))
+  ([input-id value set-input-value?]
+   (when input-id
+     (when set-input-value?
+       (when-let [input (gdom/getElement input-id)]
+         (util/set-change-value input value)))
+     (update-state! :editor/content (fn [m]
+                                      (assoc m input-id value)))
+     ;; followers
+     ;; (when-let [s (util/extract-uuid input-id)]
+     ;;   (let [input (gdom/getElement input-id)
+     ;;         leader-parent (util/rec-get-block-node input)
+     ;;         followers (->> (array-seq (js/document.getElementsByClassName s))
+     ;;                        (remove #(= leader-parent %)))]
+     ;;     (prn "followers: " (count followers))
+     ;;     ))
+)))
 
 (defn get-edit-input-id
   []