mirror of https://github.com/logseq/logseq
fix(editor): incorrect behavior of the delete key for deleting the last char
parent
3fc1560cf5
commit
369b5ece15
|
@ -684,7 +684,7 @@
|
|||
(defn safe-dec-current-pos-from-end
|
||||
[input current-pos]
|
||||
(if-let [len (and (string? input) (.-length input))]
|
||||
(when-let [input (and (>= len 2) (<= current-pos len)
|
||||
(if-let [input (and (>= len 2) (<= current-pos len)
|
||||
(.substring input (max (- current-pos 20) 0) current-pos))]
|
||||
(try
|
||||
(let [^js splitter (GraphemeSplitter.)
|
||||
|
@ -692,15 +692,16 @@
|
|||
(- current-pos (.-length (.pop input))))
|
||||
(catch :default e
|
||||
(js/console.error e)
|
||||
(dec current-pos))))
|
||||
(dec current-pos))))
|
||||
(dec current-pos)))
|
||||
(dec current-pos))
|
||||
current-pos)))
|
||||
|
||||
#?(:cljs
|
||||
;; for widen char
|
||||
(defn safe-inc-current-pos-from-start
|
||||
[input current-pos]
|
||||
(if-let [len (and (string? input) (.-length input))]
|
||||
(when-let [input (and (>= len 2) (<= current-pos len)
|
||||
(if-let [input (and (>= len 2) (<= current-pos len)
|
||||
(.substr input current-pos 20))]
|
||||
(try
|
||||
(let [^js splitter (GraphemeSplitter.)
|
||||
|
@ -708,8 +709,9 @@
|
|||
(+ current-pos (.-length (.shift input))))
|
||||
(catch :default e
|
||||
(js/console.error e)
|
||||
(inc current-pos))))
|
||||
(inc current-pos))))
|
||||
(inc current-pos)))
|
||||
(inc current-pos))
|
||||
current-pos)))
|
||||
|
||||
#?(:cljs
|
||||
(defn kill-line-before!
|
||||
|
|
|
@ -14,13 +14,17 @@
|
|||
(is (= 3 (util/safe-dec-current-pos-from-end "abc😀" 5)))
|
||||
(is (= 0 (util/safe-dec-current-pos-from-end "😀" 2)))
|
||||
(is (= 4 (util/safe-dec-current-pos-from-end "abcde" 5)))
|
||||
(is (= 1 (util/safe-dec-current-pos-from-end "中文" 2))))
|
||||
(is (= 1 (util/safe-dec-current-pos-from-end "中文" 2)))
|
||||
(is (= 0 (util/safe-dec-current-pos-from-end "中" 1)))
|
||||
(is (= 0 (util/safe-dec-current-pos-from-end "a" 1))))
|
||||
|
||||
(testing "safe current position from start for emoji"
|
||||
(is (= 5 (util/safe-inc-current-pos-from-start "abc😀d" 3)))
|
||||
(is (= 2 (util/safe-inc-current-pos-from-start "😀" 0)))
|
||||
(is (= 2 (util/safe-inc-current-pos-from-start "abcde" 1)))
|
||||
(is (= 1 (util/safe-inc-current-pos-from-start "中文" 0)))))
|
||||
(is (= 1 (util/safe-inc-current-pos-from-start "中文" 0)))
|
||||
(is (= 2 (util/safe-inc-current-pos-from-start "😀" 0)))
|
||||
(is (= 1 (util/safe-inc-current-pos-from-start "中" 0)))
|
||||
(is (= 1 (util/safe-inc-current-pos-from-start "a" 0)))))
|
||||
|
||||
(deftest test-memoize-last
|
||||
(testing "memoize-last add test"
|
||||
|
|
Loading…
Reference in New Issue