Pārlūkot izejas kodu

fix: mobile bar search command with auto complete #1010

charlie 5 gadi atpakaļ
vecāks
revīzija
df4a10375e

+ 1 - 1
src/main/frontend/commands.cljs

@@ -253,7 +253,7 @@
     (state/set-block-content-and-last-pos! id new-value new-pos)
     (util/move-cursor-to input new-pos)
     (when check-fn
-      (check-fn new-value (dec (count prefix))))))
+      (check-fn new-value (dec (count prefix)) new-pos))))
 
 (defn simple-replace!
   [id value selected

+ 12 - 2
src/main/frontend/components/editor.cljs

@@ -247,10 +247,20 @@
     {:on-click #(commands/simple-insert! parent-id "\n" {})}
     svg/multi-line-input]
    [:button.font-extrabold.bottom-action.-mt-1
-    {:on-click #(commands/simple-insert! parent-id "[[]]" {:backward-pos 2})}
+    {:on-click #(commands/simple-insert!
+                 parent-id "[[]]"
+                 {:backward-pos 2
+                  :check-fn (fn [_ _ new-pos]
+                              (reset! commands/*slash-caret-pos new-pos)
+                              (commands/handle-step [:editor/search-page]))})}
     "[[]]"]
    [:button.font-extrabold.bottom-action.-mt-1
-    {:on-click #(commands/simple-insert! parent-id "(())" {:backward-pos 2})}
+    {:on-click #(commands/simple-insert!
+                 parent-id "(())"
+                 {:backward-pos 2
+                  :check-fn (fn [_ _ new-pos]
+                              (reset! commands/*slash-caret-pos new-pos)
+                              (commands/handle-step [:editor/search-block]))})}
     "(())"]])
 
 (rum/defcs input < rum/reactive

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

@@ -161,6 +161,18 @@
      ""
      "\n")))
 
+(defn get-current-input-node
+  []
+  (let [edit-input-id (state/get-edit-input-id)]
+    (and edit-input-id (gdom/getElement edit-input-id))))
+
+(defn get-current-input-value
+  []
+  (let [edit-input-id (state/get-edit-input-id)
+        input (and edit-input-id (gdom/getElement edit-input-id))]
+    (when input
+      (gobj/get input "value"))))
+
 (defn new-file-content
   [{:block/keys [content meta dummy?] :as block} file-content value]
   (let [utf8-content (utf8/encode file-content)
@@ -2054,9 +2066,3 @@
   []
   (js/setInterval save-current-block-when-idle! 3000))
 
-(defn get-current-input-value
-  []
-  (let [edit-input-id (state/get-edit-input-id)
-        input (and edit-input-id (gdom/getElement edit-input-id))]
-    (when input
-      (gobj/get input "value"))))