浏览代码

refactor: clean duplicate methods

Weihua Lu 4 年之前
父节点
当前提交
9b3f756c6a
共有 3 个文件被更改,包括 7 次插入12 次删除
  1. 1 1
      src/main/frontend/commands.cljs
  2. 6 6
      src/main/frontend/handler/editor.cljs
  3. 0 5
      src/main/frontend/util.cljc

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

@@ -469,7 +469,7 @@
         (let [new-pos (compute-pos-delta-when-change-marker
                        current-input edit-content new-value marker (dec slash-pos))]
           ;; TODO: any performance issue?
-          (js/setTimeout #(util/set-caret-pos! current-input new-pos) 10))))))
+          (js/setTimeout #(cursor/move-cursor-to current-input new-pos) 10))))))
 
 (defmethod handle-step :editor/set-priority [[_ priority] format]
   (when-let [input-id (state/get-edit-input-id)]

+ 6 - 6
src/main/frontend/handler/editor.cljs

@@ -150,7 +150,7 @@
     (when-let [cursor-range (state/get-cursor-range)]
       (when-let [range cursor-range]
         (let [pos (diff/find-position markup range)]
-          (util/set-caret-pos! node pos))))))
+          (cursor/move-cursor-to node pos))))))
 
 (defn highlight-block!
   [block-uuid]
@@ -747,7 +747,7 @@
       (let [new-pos (commands/compute-pos-delta-when-change-marker
                      current-input content new-content marker (util/get-input-pos current-input))]
         (state/set-edit-content! edit-input-id new-content)
-        (util/set-caret-pos! current-input new-pos)))))
+        (cursor/move-cursor-to current-input new-pos)))))
 
 (defn set-marker
   [{:block/keys [uuid marker content format properties] :as block} new-marker]
@@ -2256,8 +2256,8 @@
     (cond
       (not= selected-start selected-end)
       (if up?
-        (util/set-caret-pos! input selected-start)
-        (util/set-caret-pos! input selected-end))
+        (cursor/move-cursor-to input selected-start)
+        (cursor/move-cursor-to input selected-end))
 
       (or (and up? (cursor/textarea-cursor-first-row? input))
           (and down? (cursor/textarea-cursor-last-row? input)))
@@ -2299,8 +2299,8 @@
       (cond
         (not= selected-start selected-end)
         (if left?
-          (util/set-caret-pos! input selected-start)
-          (util/set-caret-pos! input selected-end))
+          (cursor/move-cursor-to input selected-start)
+          (cursor/move-cursor-to input selected-end))
 
         (or (and left? (util/input-start? input))
             (and right? (util/input-end? input)))

+ 0 - 5
src/main/frontend/util.cljc

@@ -325,11 +325,6 @@
                  (.setEndPoint pre-caret-text-range "EndToEnd" text-range)
                  (gobj/get pre-caret-text-range "text")))))))))
 
-#?(:cljs
-   (defn set-caret-pos!
-     [input pos]
-     (.setSelectionRange input pos pos)))
-
 #?(:cljs
    (defn get-caret-pos
      [input]