Selaa lähdekoodia

fix: /query doesn't enter text

fixes LOG-3165

The editor will be saved in these cases:
1. click outside the editor
2. press `ESC`
3. clear-edit! called

Previously, 3 may not be saved.
Tienson Qin 1 vuosi sitten
vanhempi
sitoutus
148a05597b
2 muutettua tiedostoa jossa 15 lisäystä ja 16 poistoa
  1. 12 9
      src/main/frontend/components/editor.cljs
  2. 3 7
      src/main/frontend/mixins.cljs

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

@@ -830,7 +830,7 @@
              :datepicker} action)
           (and (keyword? action)
                (= (namespace action) "editor.action")))
-      (util/stop e)
+      (when e (util/stop e))
 
       ;; editor/input component handles Escape directly, so just prevent handling it here
       (= :input action)
@@ -854,14 +854,19 @@
                   ::ref (atom nil)))
    :did-mount (fn [state]
                 (state/set-editor-args! (:rum/args state))
-                state)}
+                state)
+   :will-unmount (fn [state]
+                   (let [{:keys [block value]} (editor-handler/get-state)]
+                     (when-not (= (:block/uuid block) (:editor/deleting-block @state/state)) ; don't save deleting block
+                       (editor-handler/save-block! (state/get-current-repo) (:block/uuid block) value)))
+                   state)}
   (mixins/event-mixin
    (fn [state]
      (mixins/hide-when-esc-or-outside
       state
-      :on-hide (fn [_state e type]
-                 (when (not= type :esc)
-                   (editor-on-hide state (:value (editor-handler/get-state)) type e))))))
+      {:node @(::ref state)
+       :on-hide (fn [_state e type]
+                  (editor-on-hide state (:value (editor-handler/get-state)) type e))})))
   (mixins/event-mixin setup-key-listener!)
   lifecycle/lifecycle
   [state {:keys [format block parent-block]} id config]
@@ -878,10 +883,8 @@
                :on-change         (editor-handler/editor-on-change! block id search-timeout)
                :on-paste          (paste-handler/editor-on-paste! id)
                :on-key-down       (fn [e]
-                                    (if-let [on-key-down (:on-key-down config)]
-                                      (on-key-down e)
-                                      (when (= (util/ekey e) "Escape")
-                                        (editor-on-hide state content :esc e))))
+                                    (when-let [on-key-down (:on-key-down config)]
+                                      (on-key-down e)))
                :auto-focus true
                :class heading-class}
                (some? parent-block)

+ 3 - 7
src/main/frontend/mixins.cljs

@@ -38,8 +38,8 @@
                            (let [target (.. e -target)]
                              ;; If the click target is outside of current node
                              (when (and
-                                     (not (dom/contains dom-node target))
-                                     (not (.contains (.-classList target) "ignore-outside-event")))
+                                    (not (dom/contains dom-node target))
+                                    (not (.contains (.-classList target) "ignore-outside-event")))
                                (on-hide state e :click))))]
             (when-not (false? outside?)
               (listen state js/window "mousedown" click-fn)))
@@ -102,11 +102,7 @@
              (init-callback state))
      :did-mount (fn [state]
                   (attach-listeners state)
-                  state)
-     :will-remount (fn [old-state new-state]
-                     (detach old-state)
-                     (attach-listeners new-state)
-                     new-state)})))
+                  state)})))
 
 (defn modal
   [k]