Răsfoiți Sursa

fix(mobile): node reference doesn't work when text selected

Tienson Qin 2 săptămâni în urmă
părinte
comite
606a95d6a3

+ 1 - 1
src/main/frontend/handler/editor.cljs

@@ -2790,7 +2790,7 @@
       :else
       nil)))
 
-(defn- delete-and-update [^js input start end]
+(defn delete-and-update [^js input start end]
   (util/safe-set-range-text! input "" start end)
   (state/set-edit-content! (state/get-edit-input-id) (.-value input)))
 

+ 21 - 7
src/main/mobile/components/editor_toolbar.cljs

@@ -39,6 +39,26 @@
                   text)]
       (commands/simple-insert! parent-id text' opts))))
 
+(defn- insert-page-ref!
+  []
+  (let [{:keys [block]} (editor-handler/get-state)]
+    (when block
+      (let [input (state/get-input)]
+        (state/clear-editor-action!)
+        (let [selection (editor-handler/get-selection-and-format)
+              {:keys [selection-start selection-end selection]} selection]
+          (if selection
+            (do
+              (editor-handler/delete-and-update input selection-start selection-end)
+              (editor-handler/insert (page-ref/->page-ref selection)))
+            (insert-text page-ref/left-and-right-brackets
+                         {:backward-pos 2
+                          :check-fn (fn [_ _ _]
+                                      (let [input (state/get-input)
+                                            new-pos (cursor/get-caret-pos input)]
+                                        (state/set-editor-action-data! {:pos new-pos})
+                                        (commands/handle-step [:editor/search-page])))})))))))
+
 (defn- indent-outdent-action
   [indent?]
   {:id (if indent? "indent" "outdent")
@@ -77,13 +97,7 @@
    :system-icon "parentheses"
    :icon "brackets"
    :event? true
-   :handler #(insert-text page-ref/left-and-right-brackets
-                          {:backward-pos 2
-                           :check-fn (fn [_ _ _]
-                                       (let [input (state/get-input)
-                                             new-pos (cursor/get-caret-pos input)]
-                                         (state/set-editor-action-data! {:pos new-pos})
-                                         (commands/handle-step [:editor/search-page])))})})
+   :handler insert-page-ref!})
 
 (defn- slash-action
   []