Tienson Qin пре 4 година
родитељ
комит
c81e5259e9
2 измењених фајлова са 29 додато и 25 уклоњено
  1. 2 1
      src/main/frontend/components/block.cljs
  2. 27 24
      src/main/frontend/state.cljs

+ 2 - 1
src/main/frontend/components/block.cljs

@@ -1366,7 +1366,8 @@
                    edit-input-id
                    content
                    block
-                   cursor-range))]
+                   cursor-range
+                   false))]
          ;; wait a while for the value of the caret range
          (if (util/ios?)
            (f)

+ 27 - 24
src/main/frontend/state.cljs

@@ -686,30 +686,33 @@
        :pos (util/get-input-pos (gdom/getElement edit-input-id))})))
 
 (defn set-editing!
-  [edit-input-id content block cursor-range]
-  (when edit-input-id
-    (let [block-element (gdom/getElement (string/replace edit-input-id "edit-block" "ls-block"))
-          container (util/get-block-container block-element)
-          block (if container
-                  (assoc block
-                         :block/container (gobj/get container "id"))
-                  block)
-          content (or content "")]
-
-      (swap! state
-             (fn [state]
-               (-> state
-                   (assoc-in [:editor/content edit-input-id] (string/trim content))
-                   (assoc
-                    :editor/block block
-                    :editor/editing? {edit-input-id true}
-                    :editor/last-edit-block-id edit-input-id
-                    :cursor-range cursor-range))))
-
-      (let [input (gdom/getElement edit-input-id)
-            pos (count cursor-range)]
-        (set! (.-value input) (string/trim content))
-        (util/move-cursor-to input pos)))))
+  ([edit-input-id content block cursor-range]
+   (set-editing! edit-input-id content block cursor-range true))
+  ([edit-input-id content block cursor-range move-cursor?]
+   (when edit-input-id
+     (let [block-element (gdom/getElement (string/replace edit-input-id "edit-block" "ls-block"))
+           container (util/get-block-container block-element)
+           block (if container
+                   (assoc block
+                          :block/container (gobj/get container "id"))
+                   block)
+           content (or content "")]
+
+       (swap! state
+              (fn [state]
+                (-> state
+                    (assoc-in [:editor/content edit-input-id] (string/trim content))
+                    (assoc
+                     :editor/block block
+                     :editor/editing? {edit-input-id true}
+                     :editor/last-edit-block-id edit-input-id
+                     :cursor-range cursor-range))))
+
+       (let [input (gdom/getElement edit-input-id)
+             pos (count cursor-range)]
+         (set! (.-value input) (string/trim content))
+         (when move-cursor?
+           (util/move-cursor-to input pos)))))))
 
 (defn clear-edit!
   []