浏览代码

feat: don't rename capitalization

Junyi Du 2 年之前
父节点
当前提交
70b41ad7d1
共有 2 个文件被更改,包括 13 次插入6 次删除
  1. 12 6
      src/main/frontend/handler/conversion.cljs
  2. 1 0
      src/test/frontend/db/name_sanity_test.cljs

+ 12 - 6
src/main/frontend/handler/conversion.cljs

@@ -4,7 +4,8 @@
   "For conversion logic between old version and new version"
   (:require [logseq.graph-parser.util :as gp-util]
             [frontend.util.fs :as fs-util]
-            [frontend.handler.config :refer [set-config!]]))
+            [frontend.handler.config :refer [set-config!]]
+            [frontend.util :as util]))
 
 (defn write-filename-format!
   "Return:
@@ -77,11 +78,16 @@
   ;;   It's about user's own data management decision and should be handled
   ;;   by user manually.
   ;; the 'expected' title of the user when updating from the previous format, or title will be broken in new format
-  (or (when (and (nil? prop-title)
-                 (not= old-format new-format))
-        (calc-previous-name old-format new-format file-body))
-      ;; if no break-change conversion triggered, check if file name is in an informal / outdated style.
-      (calc-current-name new-format file-body prop-title)))
+  (let [ret (or (when (and (nil? prop-title)
+                           (not= old-format new-format))
+                  (calc-previous-name old-format new-format file-body))
+                 ;; if no break-change conversion triggered, check if file name is in an informal / outdated style.
+                (calc-current-name new-format file-body prop-title))]
+    (when (and ret
+               ;; Return only when the target is different from the original file body, not only capitalization difference
+               (not= (util/page-name-sanity-lc (:target ret))
+                     (util/page-name-sanity-lc file-body)))
+      ret)))
 
 (defn calc-rename-target
   "Return the renaming status and new file body to recover the original title of the file in previous version. 

+ 1 - 0
src/test/frontend/db/name_sanity_test.cljs

@@ -102,6 +102,7 @@
 (deftest rename-tests
   ;; z: new title structure; x: old ver title; y: title property (if available)
   (are [x y z] (= z (#'conversion-handler/calc-rename-target-impl :legacy :triple-lowbar x y))
+    "aaBBcc"      "aabbcc"        nil
     "aaa.bbb.ccc" "aaa/bbb/ccc"   {:status :informal,
                                    :target "aaa___bbb___ccc",
                                    :old-title "aaa/bbb/ccc",