Przeglądaj źródła

Merge branch 'master' into enhance/refacotr-ui-x-menu

charlie 2 lat temu
rodzic
commit
a6beee353c

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

@@ -13,11 +13,21 @@
             [goog.dom :as gdom]
             [goog.dom :as gdom]
             [rum.core :as rum]))
             [rum.core :as rum]))
 
 
+
+(defn- blur-if-compositing
+  "Call blur on the textarea if it is in composition mode, let the IME commit the composing text"
+  []
+  (when-let [edit-input-id (and (state/editor-in-composition?)
+                                (state/get-edit-input-id))]
+    (let [textarea-el (gdom/getElement edit-input-id)]
+      (.blur textarea-el))))
+
 (rum/defc indent-outdent [indent? icon]
 (rum/defc indent-outdent [indent? icon]
   [:div
   [:div
    [:button.bottom-action
    [:button.bottom-action
     {:on-mouse-down (fn [e]
     {:on-mouse-down (fn [e]
                       (util/stop e)
                       (util/stop e)
+                      (blur-if-compositing)
                       (editor-handler/indent-outdent indent?))}
                       (editor-handler/indent-outdent indent?))}
     (ui/icon icon {:size ui/icon-size})]])
     (ui/icon icon {:size ui/icon-size})]])
 
 
@@ -91,7 +101,13 @@
         (command #(if (state/sub :document/mode?)
         (command #(if (state/sub :document/mode?)
                     (editor-handler/insert-new-block! nil)
                     (editor-handler/insert-new-block! nil)
                     (commands/simple-insert! parent-id "\n" {})) {:icon "arrow-back"})
                     (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 #(do
+                    (blur-if-compositing)
+                    (editor-handler/cycle-todo!))
+                 {:icon "checkbox"} true)
         (command #(mobile-camera/embed-photo parent-id) {:icon "camera"} true)
         (command #(mobile-camera/embed-photo parent-id) {:icon "camera"} true)
         (command history/undo! {:icon "rotate" :class "rotate-180"} true)
         (command history/undo! {:icon "rotate" :class "rotate-180"} true)
         (command history/redo! {:icon "rotate-clockwise" :class "rotate-180"} true)
         (command history/redo! {:icon "rotate-clockwise" :class "rotate-180"} true)

+ 19 - 2
src/main/frontend/search/db.cljs

@@ -20,8 +20,10 @@
   (some-> content
   (some-> content
           (util/search-normalize (state/enable-search-remove-accents?))))
           (util/search-normalize (state/enable-search-remove-accents?))))
 
 
-(defn block->index
-  "Convert a block to the index for searching"
+(defn- strict-block->index
+  "Convert a block to the index for searching.
+
+   Applies full text preprocessing to the content, including removing built-in properties"
   [{:block/keys [uuid page content format] :as block
   [{:block/keys [uuid page content format] :as block
     :or {format :markdown}}]
     :or {format :markdown}}]
   (when-not (> (count content) (max-len))
   (when-not (> (count content) (max-len))
@@ -32,6 +34,21 @@
          :page page
          :page page
          :content (sanitize content)}))))
          :content (sanitize content)}))))
 
 
+(defn- loose-block->index
+  "Convert a block to the index for searching
+
+   For speed, applies no preprocessing to the content"
+  [{:block/keys [uuid page content] :as block}]
+  (when-not (string/blank? content)
+    {:id (:db/id block)
+     :uuid (str uuid)
+     :page page
+     :content content}))
+
+(defonce block->index (if (util/electron?)
+                        strict-block->index
+                        loose-block->index))
+
 (defn page->index
 (defn page->index
   "Convert a page name to the index for searching (page content level)
   "Convert a page name to the index for searching (page content level)
    Generate index based on the DB content AT THE POINT OF TIME"
    Generate index based on the DB content AT THE POINT OF TIME"