fix(editor): back/forward cursor for emoji char

This commit is contained in:
charlie
2022-01-09 21:22:24 +08:00
committed by Andelf
parent 33fbb0aa1b
commit 9c89c6395b
3 changed files with 35 additions and 9 deletions

View File

@@ -1,16 +1,22 @@
(ns frontend.util-test
(:require [cljs.test :refer [deftest is testing]]
[frontend.util :refer [find-first safe-dec-current-pos-from-end]]))
[frontend.util :as util]))
(deftest test-find-first
(testing "find-first"
(is (= 1 (find-first identity [1])))))
(is (= 1 (util/find-first identity [1])))))
(deftest test-delete-emoji-current-pos
(testing "safe current position from end for emoji"
(is (= 3 (safe-dec-current-pos-from-end "abc😀d" 5)))
(is (= 3 (safe-dec-current-pos-from-end "abc😀" 5)))
(is (= 0 (safe-dec-current-pos-from-end "😀" 2)))
(is (= 4 (safe-dec-current-pos-from-end "abcde" 5)))
(is (= 1 (safe-dec-current-pos-from-end "中文" 2)))))
(is (= 3 (util/safe-dec-current-pos-from-end "abc😀d" 5)))
(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))))
(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)))))