فهرست منبع

enhance(ux): press Enter on active table name cell exit editing

Tienson Qin 5 ماه پیش
والد
کامیت
5b76ee46a3
1فایلهای تغییر یافته به همراه22 افزوده شده و 9 حذف شده
  1. 22 9
      src/main/frontend/components/views.cljs

+ 22 - 9
src/main/frontend/components/views.cljs

@@ -214,6 +214,17 @@
        (container config' row)
        [:div])]))
 
+(defn- save-block-and-focus
+  [*ref set-focus-timeout! hide-popup?]
+  (let [node (rum/deref *ref)
+        cell (util/rec-get-node node "ls-table-cell")]
+    (p/do!
+     (editor-handler/save-current-block!)
+     (when hide-popup?
+       (shui/popup-hide!))
+     (state/exit-editing-and-set-selected-blocks! [cell])
+     (set-focus-timeout! (js/setTimeout #(.focus cell) 100)))))
+
 (rum/defc block-title
   "Used on table view"
   [block* {:keys [create-new-block width row property]}]
@@ -256,9 +267,16 @@
                                           [:div.ls-table-block.flex.flex-row.items-start
                                            {:style {:width width :max-width width :margin-right "6px"}
                                             :on-click util/stop-propagation}
-                                           (block-container {:popup? true
-                                                             :view? true
-                                                             :table-block-title? true} block)])))]
+                                           (block-container
+                                            {:popup? true
+                                             :view? true
+                                             :table-block-title? true
+                                             :on-key-down
+                                             (fn [e]
+                                               (when (= (util/ekey e) "Enter")
+                                                 (util/stop e)
+                                                 (save-block-and-focus *ref set-focus-timeout! true)))}
+                                            block)])))]
                           (p/do!
                            (shui/popup-show!
                             (.closest (.-target e) ".ls-table-cell")
@@ -266,12 +284,7 @@
                             {:id :ls-table-block-editor
                              :as-mask? true
                              :on-after-hide (fn []
-                                              (let [node (rum/deref *ref)
-                                                    cell (util/rec-get-node node "ls-table-cell")]
-                                                (p/do!
-                                                 (editor-handler/save-current-block!)
-                                                 (state/exit-editing-and-set-selected-blocks! [cell])
-                                                 (set-focus-timeout! (js/setTimeout #(.focus cell) 100)))))})
+                                              (save-block-and-focus *ref set-focus-timeout! false))})
                            (editor-handler/edit-block! block :max {:container-id :unknown-container})))))))}
      (if block
        [:div.flex.flex-row