1
0
Эх сурвалжийг харах

fix: content can be lost when auto-complete page references

Close #1937
Tienson Qin 4 жил өмнө
parent
commit
5be004ebfe

+ 5 - 1
src/main/frontend/components/editor.cljs

@@ -378,7 +378,11 @@
   {:init (fn [state]
   {:init (fn [state]
            (assoc state ::heading-level (:heading-level (first (:rum/args state)))))
            (assoc state ::heading-level (:heading-level (first (:rum/args state)))))
    :did-mount (fn [state]
    :did-mount (fn [state]
-                (state/set-editor-args! (:rum/args state))
+                ;; TODO:
+                ;; if we quickly click into a block when editing another block,
+                ;; this will happen before the `will-unmount` event, which will
+                ;; lost the content in the editing block.
+                (js/setTimeout #(state/set-editor-args! (:rum/args state)) 20)
                 state)}
                 state)}
   (mixins/event-mixin setup-key-listener!)
   (mixins/event-mixin setup-key-listener!)
   (shortcut/mixin :shortcut.handler/block-editing-only)
   (shortcut/mixin :shortcut.handler/block-editing-only)

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

@@ -21,11 +21,7 @@
            (let [{:keys [on-hide format value block id repo dummy?]} (editor-handler/get-state)]
            (let [{:keys [on-hide format value block id repo dummy?]} (editor-handler/get-state)]
              (when on-hide
              (when on-hide
                (on-hide value event))
                (on-hide value event))
-             (when
-              (or (= event :esc)
-                  (= event :visibilitychange)
-                  (and (= event :click)
-                       (not (editor-handler/auto-complete?))))
+             (when (contains? #{:esc :visibilitychange :click} event)
                (state/clear-edit!))))))
                (state/clear-edit!))))))
      :node (gdom/getElement id)
      :node (gdom/getElement id)
     ;; :visibilitychange? true
     ;; :visibilitychange? true

+ 6 - 6
src/main/frontend/ui.cljs

@@ -340,12 +340,12 @@
              {:id       (str "ac-" idx)
              {:id       (str "ac-" idx)
               :class    (when (= @current-idx idx)
               :class    (when (= @current-idx idx)
                           "chosen")
                           "chosen")
-               ;; :tab-index -1
-              :on-click (fn [e]
-                          (.preventDefault e)
-                          (if (and (gobj/get e "shiftKey") on-shift-chosen)
-                            (on-shift-chosen item)
-                            (on-chosen item)))}
+              ;; :tab-index -1
+              :on-mouse-down (fn [e]
+                               (util/stop e)
+                               (if (and (gobj/get e "shiftKey") on-shift-chosen)
+                                 (on-shift-chosen item)
+                                 (on-chosen item)))}
              (if item-render (item-render item) item))
              (if item-render (item-render item) item))
             idx))]
             idx))]
        (when empty-div
        (when empty-div