Ver código fonte

fix: regression of unwanted tag pages are created as you type

Fixes LOG-2820
Tienson Qin 1 ano atrás
pai
commit
1536d9aff5

+ 2 - 1
deps/outliner/src/logseq/outliner/core.cljs

@@ -366,7 +366,8 @@
               m)
           m (cond->> m'
               db-based?
-              (db-marker-handle conn))]
+              (db-marker-handle conn))
+          m (if db-based? (dissoc m :block/tags) m)]
 
       ;; Ensure block UUID never changes
       (when (and db-id block-uuid)

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

@@ -142,8 +142,7 @@
                           (empty? matched-pages)
                           (when-not (db/page-exists? q)
                             (if db-tag?
-                              (concat [(str (t :new-page) " " q)
-                                       (str (t :new-class) " " q)]
+                              (concat [(str (t :new-class) " " q)]
                                       matched-pages)
                               (cons q matched-pages)))
 

+ 31 - 31
src/main/frontend/handler/editor.cljs

@@ -1300,37 +1300,37 @@
    (save-current-block! {}))
   ([{:keys [force? skip-properties? current-block] :as opts}]
    ;; non English input method
-   (let [result (when-not (state/editor-in-composition?)
-                  (when (state/get-current-repo)
-                    (try
-                      (let [input-id (state/get-edit-input-id)
-                            block (state/get-edit-block)
-                            db-block (when-let [block-id (:block/uuid block)]
-                                       (db/pull [:block/uuid block-id]))
-                            elem (and input-id (gdom/getElement input-id))
-                            db-content (:block/content db-block)
-                            db-content-without-heading (and db-content
-                                                            (common-util/safe-subs db-content (:block/level db-block)))
-                            value (if (= (:block/uuid current-block) (:block/uuid block))
-                                    (:block/content current-block)
-                                    (and elem (gobj/get elem "value")))]
-                        (when value
-                          (cond
-                            force?
-                            (save-block-aux! db-block value opts)
-
-                            (and skip-properties?
-                                 (db-model/top-block? block)
-                                 (when elem (thingatpt/properties-at-point elem)))
-                            nil
-
-                            (and block value db-content-without-heading
-                                 (not= (string/trim db-content-without-heading)
-                                       (string/trim value)))
-                            (save-block-aux! db-block value opts))))
-                      (catch :default error
-                        (log/error :save-block-failed error)))))]
-     result)))
+   (when-not (or (state/editor-in-composition?)
+                 (state/get-editor-action))
+     (when (state/get-current-repo)
+       (try
+         (let [input-id (state/get-edit-input-id)
+               block (state/get-edit-block)
+               db-block (when-let [block-id (:block/uuid block)]
+                          (db/pull [:block/uuid block-id]))
+               elem (and input-id (gdom/getElement input-id))
+               db-content (:block/content db-block)
+               db-content-without-heading (and db-content
+                                               (common-util/safe-subs db-content (:block/level db-block)))
+               value (if (= (:block/uuid current-block) (:block/uuid block))
+                       (:block/content current-block)
+                       (and elem (gobj/get elem "value")))]
+           (when value
+             (cond
+               force?
+               (save-block-aux! db-block value opts)
+
+               (and skip-properties?
+                    (db-model/top-block? block)
+                    (when elem (thingatpt/properties-at-point elem)))
+               nil
+
+               (and block value db-content-without-heading
+                    (not= (string/trim db-content-without-heading)
+                          (string/trim value)))
+               (save-block-aux! db-block value opts))))
+         (catch :default error
+           (log/error :save-block-failed error)))))))
 
 (defn- clean-content!
   [repo format content]

+ 6 - 3
src/main/frontend/handler/page.cljs

@@ -218,7 +218,7 @@
       (fn [chosen e]
         (util/stop e)
         (state/clear-editor-action!)
-        (let [class? (string/starts-with? chosen (t :new-class))
+        (let [class? (and db-based? hashtag?)
               chosen (-> chosen
                          (string/replace-first (str (t :new-class) " ") "")
                          (string/replace-first (str (t :new-page) " ") ""))
@@ -242,11 +242,14 @@
                          _ (when-not tag-entity
                              (<create! tag {:redirect? false
                                             :create-first-block? false
-                                            :class? class?}))]
+                                            :class? class?}))
+                         tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)])]
                    (when class?
                      (let [repo (state/get-current-repo)
                            tag-entity (or tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)]))
-                           tx-data [[:db/add [:block/uuid (:block/uuid edit-block)] :block/tags (:db/id tag-entity)]
+                           tx-data [[:db/add (:db/id tag-entity) :block/type "class"]
+                                    [:db/add [:block/uuid (:block/uuid edit-block)] :block/tags (:db/id tag-entity)]
+                                    ;; TODO: Should classes counted as refs
                                     [:db/add [:block/uuid (:block/uuid edit-block)] :block/refs (:db/id tag-entity)]]]
                        (db/transact! repo tx-data {:outliner-op :save-block})))))))
            (editor-handler/insert-command! id