fix: IME check refactor

pull/3499/head
Junyi Du 2021-12-15 13:41:00 +08:00 committed by Tienson Qin
parent 2eca2c3c75
commit 7a8527b3f8
2 changed files with 17 additions and 3 deletions

View File

@ -388,7 +388,7 @@
(when @search-timeout (when @search-timeout
(js/clearTimeout @search-timeout)) (js/clearTimeout @search-timeout))
(let [value (util/evalue e) (let [value (util/evalue e)
is-composing? (util/event-is-composing? e)] is-composing? (util/onchange-event-is-composing? e)]
(if (and (string/blank? value) (not is-composing?)) (if (and (string/blank? value) (not is-composing?))
(search-handler/clear-search! false) (search-handler/clear-search! false)
(let [search-mode (state/get-search-mode) (let [search-mode (state/get-search-mode)

View File

@ -1493,6 +1493,20 @@
#?(:cljs #?(:cljs
(defn event-is-composing? (defn event-is-composing?
"Check if keydown event is a composing (IME) event.
Ignore the IME finishing keycode by default."
([e]
(event-is-composing? e true))
([e ignore-finish?]
(let [event-composing? (gobj/getValueByKeys e "event_" "isComposing")
finish-keycode? (= (.-keyCode e) 229)]
(if ignore-finish?
(and event-composing? (not finish-keycode?))
(or event-composing? finish-keycode?))))))
#?(:cljs
(defn onchange-event-is-composing?
"Check if onchange event of Input is a composing (IME) event.
Including IME finishing."
[e] [e]
(or (gobj/getValueByKeys e "event_" "isComposing") (gobj/getValueByKeys e "nativeEvent" "isComposing"))) ;; No keycode available
(= (.-keyCode e) 229))))