Просмотр исходного кода

fix(mobile): commit composing text before cycle todo

Close #10879
Close #8503
Close #10013
Andelf 2 лет назад
Родитель
Сommit
7bad07d2bf
2 измененных файлов с 22 добавлено и 9 удалено
  1. 12 8
      src/main/frontend/handler/editor.cljs
  2. 10 1
      src/main/frontend/mobile/mobile_bar.cljs

+ 12 - 8
src/main/frontend/handler/editor.cljs

@@ -740,17 +740,21 @@
    (let [[new-content _] (marker/cycle-marker content marker new-marker format (state/get-preferred-workflow))]
      (save-block-if-changed! block new-content))))
 
+(defn cycle-todo-by-block-ids!
+  [ids]
+  (when-let [ids (filter uuid? (distinct ids))]
+    (outliner-tx/transact! {:outliner-op :cycle-todos}
+                           (doseq [id ids]
+                             (let [block (db/pull [:block/uuid id])]
+                               (when (not-empty (:block/content block))
+                                 (set-marker block)))))))
+
 (defn cycle-todos!
   []
   (when-let [blocks (seq (get-selected-blocks))]
-    (let [ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
-                                     (uuid id)) blocks))
-                   (remove nil?))]
-      (outliner-tx/transact! {:outliner-op :cycle-todos}
-        (doseq [id ids]
-          (let [block (db/pull [:block/uuid id])]
-            (when (not-empty (:block/content block))
-              (set-marker block))))))))
+    (let [ids (map #(when-let [id (dom/attr % "blockid")]
+                      (uuid id)) blocks)]
+      (cycle-todo-by-block-ids! ids))))
 
 (defn cycle-todo!
   []

+ 10 - 1
src/main/frontend/mobile/mobile_bar.cljs

@@ -91,7 +91,16 @@
         (command #(if (state/sub :document/mode?)
                     (editor-handler/insert-new-block! nil)
                     (commands/simple-insert! parent-id "\n" {})) {:icon "arrow-back"})
-        (command editor-handler/cycle-todo! {:icon "checkbox"} true)
+        ;; On mobile devies, some IME(keyboard) uses composing mode.
+        ;; The composing text can be committed by losing focus.
+        ;; 100ms is enough to commit the composing text to db.
+        (command #(when-let [block-id (:block/uuid (state/get-edit-block))]
+                    (editor-handler/escape-editing true)
+                    (js/setTimeout
+                     (fn []
+                       (editor-handler/cycle-todo-by-block-ids! [block-id]))
+                     100))
+                 {:icon "checkbox"} true)
         (command #(mobile-camera/embed-photo parent-id) {:icon "camera"} true)
         (command history/undo! {:icon "rotate" :class "rotate-180"} true)
         (command history/redo! {:icon "rotate-clockwise" :class "rotate-180"} true)