瀏覽代碼

enhance: jump to edit the first block when creating a new page

Tienson Qin 4 年之前
父節點
當前提交
7a78e805fd
共有 3 個文件被更改,包括 29 次插入24 次删除
  1. 1 4
      src/main/frontend/components/block.cljs
  2. 26 17
      src/main/frontend/components/page.cljs
  3. 2 3
      src/main/frontend/handler/editor.cljs

+ 1 - 4
src/main/frontend/components/block.cljs

@@ -1238,7 +1238,7 @@
         priority]
        (if title
          (map-inline config title)
-         [[:span.opacity-50 "Click here to start writing"]])
+         [[:span.opacity-50 "Click here to start writing, type '/' to see all the commands."]])
        [tags])))))
 
 (defn show-dnd-separator
@@ -1418,9 +1418,6 @@
         (merge attrs))
 
       (cond
-        dummy?
-        [:span.opacity-50 "Click here to start writing"]
-
         (seq title)
         (build-block-title config block)
 

+ 26 - 17
src/main/frontend/components/page.cljs

@@ -54,6 +54,31 @@
         (page-handler/add-page-to-recent! repo page-original-name)
         (db/get-page-blocks repo page-name)))))
 
+(rum/defc page-blocks-inner <
+  {:did-mount (fn [state]
+                (let [block (first (nth (:rum/args state) 1))]
+                  (when (:block/dummy? block)
+                    (editor-handler/edit-block! block 0 (:block/format block) (:block/uuid block))))
+                state)}
+  [page-name page-blocks hiccup sidebar?]
+  [:div.page-blocks-inner
+   ;; (when (and (seq grouped-blocks-by-file)
+   ;;            (> (count grouped-blocks-by-file) 1))
+   ;;   (ui/admonition
+   ;;    :warning
+   ;;    [:div.text-sm
+   ;;     [:p.font-medium "Those pages have the same title, you might want to only keep one file."]
+   ;;     [:ol
+   ;;      (for [[file-path blocks] (into (sorted-map) grouped-blocks-by-file)]
+   ;;        [:li [:a {:key file-path
+   ;;                  :href (rfe/href :file {:path file-path})} file-path]])]]))
+
+   (rum/with-key
+     (content/content page-name
+                      {:hiccup   hiccup
+                       :sidebar? sidebar?})
+     (str page-name "-hiccup"))])
+
 (rum/defc page-blocks-cp < rum/reactive
   db-mixins/query
   [repo page file-path page-name page-original-name encoded-page-name sidebar? journal? block? block-id format]
@@ -78,23 +103,7 @@
                        :editor-box editor/box}
         hiccup-config (common-handler/config-with-document-mode hiccup-config)
         hiccup (block/->hiccup page-blocks hiccup-config {})]
-    [:div.page-blocks-inner
-     ;; (when (and (seq grouped-blocks-by-file)
-     ;;            (> (count grouped-blocks-by-file) 1))
-     ;;   (ui/admonition
-     ;;    :warning
-     ;;    [:div.text-sm
-     ;;     [:p.font-medium "Those pages have the same title, you might want to only keep one file."]
-     ;;     [:ol
-     ;;      (for [[file-path blocks] (into (sorted-map) grouped-blocks-by-file)]
-     ;;        [:li [:a {:key file-path
-     ;;                  :href (rfe/href :file {:path file-path})} file-path]])]]))
-
-     (rum/with-key
-       (content/content page-name
-                        {:hiccup   hiccup
-                         :sidebar? sidebar?})
-       (str encoded-page-name "-hiccup"))]))
+    (page-blocks-inner page-name page-blocks hiccup sidebar?)))
 
 (defn contents-page
   [{:block/keys [name original-name file] :as contents}]

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

@@ -225,9 +225,8 @@
                           (subs content 0 pos))
              content (text/remove-built-in-properties! (:block/format block)
                                                        content)]
-         (do
-           (clear-selection! nil)
-           (state/set-editing! edit-input-id content block text-range move-cursor?)))))))
+         (clear-selection! nil)
+         (state/set-editing! edit-input-id content block text-range move-cursor?))))))
 
 (defn edit-last-block-for-new-page!
   [last-block pos]