Browse Source

fix(editor): add to contents page

Also, editing should be faster now.
Tienson Qin 5 years ago
parent
commit
efe4867e08
2 changed files with 9 additions and 6 deletions
  1. 1 1
      src/main/frontend/components/editor.cljs
  2. 8 5
      src/main/frontend/handler/page.cljs

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

@@ -495,7 +495,7 @@
                  value (gobj/get input "value")
                  ctrlKey (gobj/get e "ctrlKey")
                  metaKey (gobj/get e "metaKey")
-                 pos (:pos (util/get-caret-pos input))]
+                 pos (util/get-input-pos input)]
              (cond
                (or ctrlKey metaKey)
                nil

+ 8 - 5
src/main/frontend/handler/page.cljs

@@ -376,13 +376,17 @@
         last-empty? (>= 3 (count (:block/content last-block)))
         heading-pattern (config/get-block-pattern (state/get-preferred-format))
         pre-str (str heading-pattern heading-pattern)
-        new-content (if last-empty? (str pre-str " [[" page-name "]]") (str (:block/content last-block) pre-str " [[" page-name "]]"))]
+        new-content (if last-empty?
+                      (str pre-str " [[" page-name "]]")
+                      (str (string/trimr (:block/content last-block))
+                           "\n"
+                           pre-str " [[" page-name "]]"))]
     (editor-handler/insert-new-block-aux!
      last-block
      new-content
      {:create-new-block? false
       :ok-handler
-      (fn [[_first-block last-block _new-block-content]]
+      (fn [_]
         (notification/show! "Added to contents!" :success)
         (editor-handler/clear-when-saved!))
       :with-level? true
@@ -470,7 +474,6 @@
         new-pages (take 12 (distinct (cons page pages)))]
     (db/set-key-value repo :recent/pages new-pages)))
 
-
 (defn template-exists?
   [title]
   (when title
@@ -489,5 +492,5 @@
          (reverse)
          (remove (fn [[page modified-at]]
                    (or (util/file-page? page)
-                     (and modified-at
-                       (> modified-at now-long))))))))
+                       (and modified-at
+                            (> modified-at now-long))))))))