Przeglądaj źródła

fix(editor): properties save and clearing content when backspace

Closed https://github.com/logseq/logseq/issues/542
Tienson Qin 5 lat temu
rodzic
commit
51dfe14314
3 zmienionych plików z 16 dodań i 9 usunięć
  1. 1 1
      src/main/frontend/handler/editor.cljs
  2. 11 4
      src/main/frontend/text.cljs
  3. 4 4
      yarn.lock

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

@@ -414,7 +414,7 @@
                           (assoc new-properties :old_permalink (:permalink old-properties))
                           new-properties)
          value (cond
-                 custom-properties
+                 (seq custom-properties)
                  (text/re-construct-block-properties block value custom-properties)
 
                  (and (seq (:block/properties block))

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

@@ -47,10 +47,17 @@
   (let [lines (string/split-lines content)
         [title-lines properties-and-body] (split-with (fn [l] (not (string/starts-with? (string/upper-case (string/triml l)) ":PROPERTIES:"))) lines)
         body (drop-while (fn [l]
-                           (or
-                            (string/starts-with? (string/triml l) ":") ; kv
-                            (string/starts-with? (string/upper-case (string/triml l)) ":end:")))
-                         properties-and-body)]
+                           (let [l' (string/lower-case (string/trim l))]
+                             (and (string/starts-with? l' ":")
+                                  (not (string/starts-with? l' ":end:")))))
+                         properties-and-body)
+        body (if (and (seq body)
+                      (string/starts-with? (string/lower-case (string/triml (first body))) ":end:"))
+               (let [line (string/replace (first body) #"(?i):end:\s?" "")]
+                 (if (string/blank? line)
+                   (rest body)
+                   (cons line (rest body))))
+               body)]
     (->> (concat title-lines body)
          (string/join "\n"))))
 

+ 4 - 4
yarn.lock

@@ -3643,10 +3643,10 @@ xtend@^4.0.0, xtend@^4.0.2:
   resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b"
   integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==
 
-yargs-parser@^11.1.1:
-  version "11.1.1"
-  resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-11.1.1.tgz#879a0865973bca9f6bab5cbdf3b1c67ec7d3bcf4"
-  integrity sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ==
+yargs-parser@^13.1.2:
+  version "13.1.2"
+  resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38"
+  integrity sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg==
   dependencies:
     camelcase "^5.0.0"
     decamelize "^1.2.0"