Przeglądaj źródła

fix: unwanted tag pages are created as you type

Fixes LOG-2820
Tienson Qin 2 lat temu
rodzic
commit
4f9f91b6d1

+ 14 - 0
src/main/frontend/handler/page.cljs

@@ -218,12 +218,26 @@
                                (subs q 1)
                                q))
               last-pattern (str "#" (when wrapped? page-ref/left-brackets) last-pattern)]
+          (when (config/db-based-graph? (state/get-current-repo))
+            (let [tag (string/trim q)
+                  edit-block (state/get-edit-block)]
+              (when (and (not (string/blank? tag)) edit-block)
+                (let [tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)])]
+                  (when-not tag-entity
+                    (create! tag {:redirect? false
+                                  :create-first-block? false
+                                  :class? true}))
+                  (let [tag-entity (or tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)]))]
+                    (db/transact! [[:db/add (:db/id edit-block) :block/tags (:db/id tag-entity)]
+                                   [:db/add (:db/id edit-block) :block/refs (:db/id tag-entity)]]))))))
+
           (editor-handler/insert-command! id
                                           (str "#" (when wrapped? page-ref/left-brackets) chosen)
                                           format
                                           {:last-pattern last-pattern
                                            :end-pattern (when wrapped? page-ref/right-brackets)
                                            :command :page-ref})
+
           (when input (.focus input))))
       (fn [chosen e]
         (util/stop e)

+ 5 - 4
src/main/frontend/modules/outliner/core.cljs

@@ -305,7 +305,8 @@
                                                           (str config/page-ref-special-chars (:block/uuid tag))))
                                                       (:block/tags m))
                                                      (remove nil?)))))
-              m)]
+              m)
+          m-without-tags (if db-based? (dissoc m :block/tags) m)]
       (when id
         ;; Retract attributes to prepare for tx which rewrites block attributes
         (let [retract-attributes (when db-based?
@@ -318,10 +319,10 @@
                                            retract-attributes))))))
 
         ;; Update block's page attributes
-        (update-page-when-save-block txs-state block-entity m)
+        (update-page-when-save-block txs-state block-entity m-without-tags)
 
         ;; Remove orphaned refs from block
-        (remove-orphaned-refs-when-save txs-state block-entity m))
+        (remove-orphaned-refs-when-save txs-state block-entity m-without-tags))
 
       ;; handle others txs
       (let [other-tx (:db/other-tx m)]
@@ -329,7 +330,7 @@
           (swap! txs-state (fn [txs]
                              (vec (concat txs other-tx)))))
         (swap! txs-state conj
-               (dissoc m :db/other-tx)))
+               (dissoc m-without-tags :db/other-tx)))
 
       (create-object-when-save txs-state block-entity m structured-tags?)