浏览代码

fix commands menu not updating on Android (#5936)

* fix commands menu not updating on Android

* handle digit key
llcc 3 年之前
父节点
当前提交
3484902764
共有 1 个文件被更改,包括 26 次插入7 次删除
  1. 26 7
      src/main/frontend/handler/editor.cljs

+ 26 - 7
src/main/frontend/handler/editor.cljs

@@ -2790,17 +2790,36 @@
   [_state input input-id search-timeout]
   [_state input input-id search-timeout]
   (fn [e key-code]
   (fn [e key-code]
     (when-not (util/event-is-composing? e)
     (when-not (util/event-is-composing? e)
-      (let [k (gobj/get e "key")
-            code (gobj/getValueByKeys e "event_" "code")
-            format (:format (get-state))
-            current-pos (cursor/pos input)
+      (let [current-pos (cursor/pos input)
             value (gobj/get input "value")
             value (gobj/get input "value")
             c (util/nth-safe value (dec current-pos))
             c (util/nth-safe value (dec current-pos))
+            [key-code k code is-processed?]
+            (if (and (mobile-util/native-android?)
+                     (or (= key-code 229)
+                         (= key-code 0)))
+              [(.charCodeAt value (dec current-pos))
+               c
+               (cond
+                 (= c " ")
+                 "Space"
+
+                 (parse-long c)
+                 (str "Digit" c)
+
+                 :else
+                 (str "Key" (string/upper-case c)))
+               false]
+              [key-code
+               (gobj/get e "key")
+               (if (mobile-util/native-android?)
+                 (gobj/get e "key")
+                 (gobj/getValueByKeys e "event_" "code"))
+               (util/event-is-composing? e true)]) ;; #3440
+            format (:format (get-state))
             last-key-code (state/get-last-key-code)
             last-key-code (state/get-last-key-code)
             blank-selected? (string/blank? (util/get-selected-text))
             blank-selected? (string/blank? (util/get-selected-text))
-            is-processed? (util/event-is-composing? e true) ;; #3440
             non-enter-processed? (and is-processed? ;; #3251
             non-enter-processed? (and is-processed? ;; #3251
-                                      (not= code keycode/enter-code)) ;; #3459
+                                      (not= code keycode/enter-code))  ;; #3459
             editor-action (state/get-editor-action)]
             editor-action (state/get-editor-action)]
         (cond
         (cond
           (and (= :commands (state/get-editor-action)) (not= k (state/get-editor-command-trigger)))
           (and (= :commands (state/get-editor-action)) (not= k (state/get-editor-command-trigger)))
@@ -2813,7 +2832,7 @@
           (let [matched-block-commands (get-matched-block-commands input)]
           (let [matched-block-commands (get-matched-block-commands input)]
             (if (seq matched-block-commands)
             (if (seq matched-block-commands)
               (cond
               (cond
-                (= key-code 9)       ;tab
+                (= key-code 9)          ;tab
                 (do
                 (do
                   (util/stop e)
                   (util/stop e)
                   (insert-command! input-id
                   (insert-command! input-id