浏览代码

enhance(properties): Enter to create new value

Tienson Qin 2 年之前
父节点
当前提交
8e87913f1f
共有 2 个文件被更改,包括 39 次插入14 次删除
  1. 1 1
      src/main/frontend/components/content.cljs
  2. 38 13
      src/main/frontend/components/property.cljs

+ 1 - 1
src/main/frontend/components/content.cljs

@@ -372,7 +372,7 @@
        (ui/menu-link
         {:key "Configure this property"
          :on-click (fn []
-                     (state/set-modal! #(property/property-config repo property)))}
+                     (state/set-modal! #(property/property-config repo property {})))}
         (t :context-menu/configure-property)
         nil))
     (ui/menu-link

+ 38 - 13
src/main/frontend/components/property.cljs

@@ -314,20 +314,45 @@
            [:div.h-6 (select-block block property select-opts)]
 
            (let [config {:editor-opts
-                         {:on-key-down
+                         {:on-blur
                           (fn [e]
-                            (when (and (contains? #{"Enter" "Escape"} (util/ekey e))
-                                       (not (state/get-editor-action)))
-                              (util/stop e)
-                              (property-handler/set-block-property! repo (:block/uuid block)
-                                                                    (:block/original-name property)
-                                                                    (util/evalue e)
-                                                                    :old-value value)
-                              (when editing-atom (reset! editing-atom false))
-                              (exit-edit-property)))}}]
-             [:div.pl-1 (editor-box editor-args editor-id (cond-> config
-                                                            multiple-values?
-                                                            (assoc :property-value value)))]))]
+                            (let [new-value (util/evalue e)
+                                  blank? (string/blank? new-value)]
+                              (when (not (state/get-editor-action))
+                                (util/stop e)
+                                (when-not blank?
+                                  (property-handler/set-block-property! repo (:block/uuid block)
+                                                                        (:block/original-name property)
+                                                                        new-value
+                                                                        :old-value value))
+                                (exit-edit-property)
+                                (when editing-atom (reset! editing-atom false)))))
+                          :on-key-down
+                          (fn [e]
+                            (let [new-value (util/evalue e)
+                                  blank? (string/blank? new-value)]
+                              (when (and (contains? #{"Enter" "Escape"} (util/ekey e))
+                                         (not (state/get-editor-action)))
+                                (util/stop e)
+                                (when-not blank?
+                                  (property-handler/set-block-property! repo (:block/uuid block)
+                                                                        (:block/original-name property)
+                                                                        new-value
+                                                                        :old-value value))
+                                (exit-edit-property)
+                                (cond
+                                  (or blank?
+                                      (and editing-atom
+                                           (not= type :default)))
+                                  (reset! editing-atom false)
+
+                                  (and editing-atom @editing-atom)
+                                  (some-> (gdom/getElement editor-id)
+                                          (util/set-change-value ""))))))}}]
+             [:div.pl-1
+              (editor-box editor-args editor-id (cond-> config
+                                                  multiple-values?
+                                                  (assoc :property-value value)))]))]
         (let [class (str (when-not row? "flex flex-1 ")
                          (when multiple-values? "property-value-content"))]
           [:div {:id (or dom-id (random-uuid))