fix: can't move forward if there's only one character in the editor

close #3952
This commit is contained in:
Tienson Qin
2022-01-20 11:12:14 +08:00
parent ab324ba7f1
commit 27caa5d576

View File

@@ -71,8 +71,9 @@
([input n]
(when input
(let [{:keys [pos]} (get-caret-pos input)
pos (if (= n 1)
(util/safe-inc-current-pos-from-start (.-value input) pos)
pos (if (and (= n 1) (not (zero? pos)))
(or (util/safe-inc-current-pos-from-start (.-value input) pos)
(inc pos))
(+ pos n))]
(move-cursor-to input pos)))))
@@ -84,7 +85,8 @@
(let [{:keys [pos]} (get-caret-pos input)
pos (if (= n 1)
(util/safe-dec-current-pos-from-end (.-value input) pos)
(- pos n))]
(- pos n))
pos (max 0 (or pos (dec pos)))]
(move-cursor-to input pos)))))
(defn- get-input-content&pos