Просмотр исходного кода

Merge branch 'feat/db' into feat/namespace

Tienson Qin 1 год назад
Родитель
Сommit
7e26022c8b

+ 3 - 1
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -437,10 +437,12 @@
                                        result (cond->> m
                                                 (and db-based? tag? (not (:db/ident m)))
                                                 (db-class/build-new-class db))
-                                       page-name (:block/name result)
+                                       page-name (if db-based? (:block/title result) (:block/name result))
                                        id (get @*name->id page-name)]
                                    (when (nil? id)
                                      (swap! *name->id assoc page-name (:block/uuid result)))
+                                   ;; Changing a :block/uuid should be done cautiously here as it can break
+                                   ;; the identity of built-in concepts in db graphs
                                    (if id
                                      (assoc result :block/uuid id)
                                      result))))) col)))

+ 25 - 13
deps/outliner/src/logseq/outliner/core.cljs

@@ -209,21 +209,33 @@
     (file-rebuild-block-refs repo db date-formatter block)))
 
 (defn- fix-tag-ids
-  "Updates :block/tags to reference ids from :block/refs"
-  [m]
+  "Fix or remove tags related when entered via `Escape`"
+  [m {:keys [db-graph?]}]
   (let [refs (set (map :block/name (seq (:block/refs m))))
         tags (seq (:block/tags m))]
     (if (and refs tags)
-      (update m :block/tags (fn [tags]
-                              (map (fn [tag]
-                                     (if (contains? refs (:block/name tag))
-                                       (assoc tag :block/uuid
-                                              (:block/uuid
-                                               (first (filter (fn [r] (= (:block/name tag)
-                                                                         (:block/name r)))
-                                                              (:block/refs m)))))
-                                       tag))
-                                   tags)))
+      (update m :block/tags
+              (fn [tags]
+                (cond->>
+                 ;; Update :block/tag to reference ids from :block/refs
+                 (map (fn [tag]
+                        (if (contains? refs (:block/name tag))
+                          (assoc tag :block/uuid
+                                 (:block/uuid
+                                  (first (filter (fn [r] (= (:block/name tag)
+                                                            (:block/name r)))
+                                                 (:block/refs m)))))
+                          tag))
+                      tags)
+
+                  db-graph?
+                  ;; Remove tags changing case with `Escape`
+                  ((fn [tags']
+                     (let [ref-titles (set (map :block/title (:block/refs m)))
+                           lc-ref-titles (set (map string/lower-case ref-titles))]
+                       (remove #(and (not (contains? ref-titles (:block/title %)))
+                                     (contains? lc-ref-titles (string/lower-case (:block/title %))))
+                               tags')))))))
       m)))
 
 (defn- remove-tags-when-title-changed
@@ -349,7 +361,7 @@
                          :block.temp/ast-title :block.temp/ast-body :block/level :block.temp/fully-loaded?)
                  common-util/remove-nils
                  block-with-updated-at
-                 fix-tag-ids)
+                 (fix-tag-ids {:db-graph? db-based?}))
           db @conn
           db-id (:db/id this)
           block-uuid (:block/uuid this)

+ 4 - 3
scripts/src/logseq/tasks/dev/lint.clj

@@ -29,6 +29,7 @@
         dir-to-files (->> (shell {:out :string} "git diff --name-only")
                           :out
                           string/split-lines
+                          (filter #(re-find #"\.(cljs|clj|cljc)$" %))
                           (group-by #(first (re-find dir-regex %)))
                           ;; remove files that aren't in a kondo dir
                           ((fn [x] (dissoc x nil))))]
@@ -37,10 +38,10 @@
           (let [dir (if (= dir* "src") "." dir*)
                 files (mapv #(string/replace-first % (str dir "/") "") files*)
                 cmd (str "cd " dir " && clj-kondo --lint " (string/join " " files))
-               _ (println cmd)
-               res (apply shell {:dir dir :continue :true} "clj-kondo --lint" files)]
+                _ (println cmd)
+                res (apply shell {:dir dir :continue :true} "clj-kondo --lint" files)]
            (when (pos? (:exit res)) (System/exit (:exit res)))))
-        (println "No files have changed to lint."))))
+        (println "No clj* files have changed to lint."))))
 
 (defn- validate-frontend-not-in-worker
   []

+ 4 - 0
src/main/frontend/modules/outliner/ui.cljc

@@ -17,6 +17,10 @@
            ~@body
            (let [r# (persistent! frontend.modules.outliner.op/*outliner-ops*)
                  worker# @state/*db-worker]
+            ;;  (js/console.groupCollapsed "ui/transact!")
+            ;;  (prn :ops r#)
+            ;;  (js/console.trace)
+            ;;  (js/console.groupEnd)
              (if test?#
                (when (seq r#)
                  (logseq.outliner.op/apply-ops! (state/get-current-repo)