فهرست منبع

fix: codemirror not working well with block timestamps

Related to #1013
Tienson Qin 4 سال پیش
والد
کامیت
1c4014d573
2فایلهای تغییر یافته به همراه11 افزوده شده و 6 حذف شده
  1. 6 2
      src/main/frontend/handler/editor.cljs
  2. 5 4
      src/main/frontend/text.cljs

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

@@ -327,7 +327,10 @@
 
 (defn- block-with-title
   [content format]
-  (let [content-without-level-spaces (text/remove-level-spaces content format)
+  (let [content-without-level-spaces (-> (text/remove-level-spaces content format))
+        content-without-level-spaces (str (when (= \n (first content-without-level-spaces))
+                                            "\n")
+                                          (string/trim content-without-level-spaces))
         first-block (-> content-without-level-spaces
                         (format/to-edn format)
                         ffirst)]
@@ -400,7 +403,8 @@
 (defn- with-time-properties
   [block properties]
   (if (and (state/enable-block-time?)
-           (not (:block/pre-block? block)))
+           (not (:block/pre-block? block))
+           (not= "Src" (ffirst (:block/body block))))
     (let [time (util/time-ms)
           props (into {} (:block/properties block))]
       (merge properties

+ 5 - 4
src/main/frontend/text.cljs

@@ -70,7 +70,7 @@
   [text format]
   (if-not (string/blank? text)
     (let [pattern (util/format
-                   "^[%s]+\\s?"
+                   "^[%s]+\\s?\n?"
                    (config/get-block-pattern format))
           matched-text (re-find (re-pattern pattern) text)]
       (if matched-text
@@ -145,7 +145,8 @@
   ([content properties {:keys [remove-blank? block-with-title?]
                         :or {remove-blank? true
                              block-with-title? true}}]
-   (let [properties (if (= (get properties "heading") "false")
+   (let [content (string/triml content)
+         properties (if (= (get properties "heading") "false")
                       (dissoc properties "heading")
                       properties)
          properties (if remove-blank?
@@ -197,8 +198,8 @@
                    (remove-level-spaces format true)
                    (remove-properties!)
                    (rejoin-properties properties {:block-with-title? block-with-title?}))]
-    (str level-spaces
-         (when-not block-with-title? "\n")
+    (str (when level-spaces (string/trim-newline level-spaces))
+         (when (not block-with-title?) "\n")
          (string/triml result))))
 
 (defn insert-property