1
0
Эх сурвалжийг харах

fix: Don't show 'New page' in page autocompletion for

an existing tag or property. This made sense when pages were split by
type but it doesn't make sense now that a Tag or Property can be a Page.
The 'New page' that showed up was also buggy as it didn't actually
create a new page. Also fixed page-exists? doing a case sensitive check
when a Page and Tag were in the same tags
Gabriel Horner 10 сар өмнө
parent
commit
bc0f63694a

+ 6 - 5
deps/db/src/logseq/db.cljs

@@ -201,9 +201,10 @@
   [db page-name tags]
   (when page-name
     (if (db-based-graph? db)
-      ;; Classes and properties are case sensitive
-      (let [tags (if (coll? tags) (set tags) #{tags})]
-        (if (seq (set/intersection #{:logseq.class/Tag :logseq.class/Property} tags))
+      (let [tags' (if (coll? tags) (set tags) #{tags})]
+        ;; Classes and properties are case sensitive and can be looked up
+        ;; as such in case-sensitive contexts e.g. no Page
+        (if (and (seq tags') (every? #{:logseq.class/Tag :logseq.class/Property} tags'))
           (seq
            (d/q
             '[:find [?p ...]
@@ -214,7 +215,7 @@
               [?tag :db/ident ?tag-ident]]
             db
             page-name
-            tags))
+            tags'))
           ;; TODO: Decouple db graphs from file specific :block/name
           (seq
            (d/q
@@ -226,7 +227,7 @@
               [?tag :db/ident ?tag-ident]]
             db
             (common-util/page-name-sanity-lc page-name)
-            tags))))
+            tags'))))
       (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))))
 
 (defn get-page

+ 8 - 2
src/main/frontend/components/editor.cljs

@@ -35,7 +35,8 @@
             [logseq.shui.ui :as shui]
             [promesa.core :as p]
             [react-draggable]
-            [rum.core :as rum]))
+            [rum.core :as rum]
+            [logseq.db.frontend.class :as db-class]))
 
 (defn filter-commands
   [page? commands]
@@ -156,7 +157,12 @@
                            ;; reorder, shortest and starts-with first.
                            (let [matched-pages-with-new-page
                                  (fn [partial-matched-pages]
-                                   (if (or (db/page-exists? q (if db-tag? #{:logseq.class/Tag} #{:logseq.class/Page}))
+                                   (if (or (db/page-exists? q (if db-tag?
+                                                                #{:logseq.class/Tag}
+                                                                ;; Page existence here should be the same as entity-util/page?.
+                                                                ;; Don't show 'New page' if a page has any of these tags
+                                                                (into #{:logseq.class/Page :logseq.class/Tag :logseq.class/Property}
+                                                                      db-class/page-children-classes)))
                                            (and db-tag? (some ldb/class? (:block/_alias (db/get-page q)))))
                                      partial-matched-pages
                                      (if db-tag?