Browse Source

fix(mobile): wrong cursor restore when indent or outdent

leizhe 4 years ago
parent
commit
925f764730

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

@@ -235,6 +235,7 @@
        [:button.bottom-action
         {:on-mouse-down (fn [e]
                           (util/stop e)
+                          (state/set-state! :editor/pos (cursor/pos (state/get-input)))
                           (editor-handler/indent-outdent true))}
         (ui/icon "arrow-bar-right"
                  {:style {:fontSize ui/icon-size}})]]
@@ -242,6 +243,7 @@
        [:button.bottom-action
         {:on-mouse-down (fn [e]
                           (util/stop e)
+                          (state/set-state! :editor/pos (cursor/pos (state/get-input)))
                           (editor-handler/indent-outdent false))}
         (ui/icon "arrow-bar-left"
                  {:style {:fontSize ui/icon-size}})]]

+ 5 - 2
src/main/frontend/handler/editor.cljs

@@ -176,8 +176,11 @@
   (when-let [node (gdom/getElement (str id))]
     (when-let [cursor-range (state/get-cursor-range)]
       (when-let [range cursor-range]
-        (let [pos (diff/find-position markup range)]
-          (cursor/move-cursor-to node pos))))))
+        (let [pos (:editor/pos @state/state)
+              pos (or pos (diff/find-position markup range))]
+          (cursor/move-cursor-to node pos)
+          (state/set-state! :editor/pos nil))))))
+
 
 (defn highlight-block!
   [block-uuid]

+ 1 - 0
src/main/frontend/state.cljs

@@ -108,6 +108,7 @@
       :editor/block-dom-id nil
       :editor/set-timestamp-block nil
       :editor/last-input-time nil
+      :editor/pos nil
       :editor/document-mode? document-mode?
       :editor/args nil
       :editor/on-paste? false