Jelajahi Sumber

fix: rename related properties when renaming the page

Tienson Qin 3 tahun lalu
induk
melakukan
5d7925115d

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

@@ -248,7 +248,7 @@
          matched-properties
          {:on-chosen (editor-handler/property-on-chosen-handler id q)
           :on-enter non-exist-handler
-          :empty-placeholder [:div.text-gray-500.px-4.py-2.text-sm "Search for a property"]
+          :empty-placeholder [:div.px-4.py-2.text-sm (str "Create a new property: " q)]
           :header [:div.px-4.py-2.text-sm.font-medium "Matched properties: "]
           :item-render (fn [property] property)
           :class       "black"})))))

+ 4 - 10
src/main/frontend/handler/editor.cljs

@@ -1773,8 +1773,7 @@
 (defn close-autocomplete-if-outside
   [input]
   (when (and input
-             (or (state/get-editor-action)
-                 (state/get-editor-show-page-search-hashtag?))
+             (state/get-editor-action)
              (not (wrapped-by? input "[[" "]]")))
     (when (get-search-q)
       (let [value (gobj/get input "value")
@@ -1787,9 +1786,7 @@
                     (string/includes? between "]")
                     (string/includes? between "(")
                     (string/includes? between ")")))
-          (state/set-editor-show-block-search! false)
-          (state/set-editor-show-page-search! false)
-          (state/set-editor-show-page-search-hashtag! false))))))
+          (state/clear-editor-action!))))))
 
 (defn resize-image!
   [block-id metadata full_text size]
@@ -2800,11 +2797,8 @@
                (= c (util/nth-safe value (dec (dec current-pos))) " "))
           (state/clear-editor-action!)
 
-          (and (= c " ")
-               (or (= (util/nth-safe value (dec (dec current-pos))) "#")
-                   (not (state/get-editor-show-page-search?))
-                   (and (state/get-editor-show-page-search?)
-                        (not= (util/nth-safe value current-pos) "]"))))
+          (and (state/get-editor-show-page-search-hashtag?)
+               (= c " "))
           (state/set-editor-show-page-search-hashtag! false)
 
           :else

+ 12 - 1
src/main/frontend/handler/page.cljs

@@ -240,13 +240,21 @@
         (util/replace-ignore-case (str " " old-tag " ") (str " " new-tag " "))
         (util/replace-ignore-case (str " " old-tag "$") (str " " new-tag)))))
 
+(defn- replace-property-ref!
+  [content old-name new-name]
+  (let [new-name (keyword (string/replace (string/lower-case new-name) #"\s+" "_"))
+        old-property (str old-name "::")
+        new-property (str (name new-name) "::")]
+    (util/replace-ignore-case content old-property new-property)))
+
 (defn- replace-old-page!
   "Unsanitized names"
   [content old-name new-name]
   (when (and (string? content) (string? old-name) (string? new-name))
     (-> content
         (replace-page-ref! old-name new-name)
-        (replace-tag-ref! old-name new-name))))
+        (replace-tag-ref! old-name new-name)
+        (replace-property-ref! old-name new-name))))
 
 (defn- walk-replace-old-page!
   "Unsanitized names"
@@ -265,6 +273,9 @@
                        new-name
                        (replace-old-page! f old-name new-name))
 
+                     (and (keyword f) (= (name f) old-name))
+                     (keyword (string/replace (string/lower-case new-name) #"\s+" "_"))
+
                      :else
                      f))
                  form))

+ 1 - 0
src/main/frontend/state.cljs

@@ -588,6 +588,7 @@
 
 (defn set-editor-action!
   [value]
+  (js/console.trace)
   (set-state! :editor/action value))
 
 (defn set-editor-action-data!