Explorar el Código

fix: esc doesn't save tags

Tienson Qin hace 1 año
padre
commit
b1aae957e0

+ 2 - 0
deps/db/src/logseq/db/frontend/content.cljs

@@ -78,7 +78,9 @@
    (reduce
    (reduce
     (fn [content tag]
     (fn [content tag]
       (-> content
       (-> content
+          (string/replace (str "#" tag " ") "")
           (string/replace (str "#" tag) "")
           (string/replace (str "#" tag) "")
+          (string/replace (str "#" page-ref/left-brackets tag page-ref/right-brackets " ") "")
           (string/replace (str "#" page-ref/left-brackets tag page-ref/right-brackets) "")))
           (string/replace (str "#" page-ref/left-brackets tag page-ref/right-brackets) "")))
     content
     content
     tags)
     tags)

+ 10 - 2
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -349,7 +349,8 @@
          form))
          form))
      (concat title body))
      (concat title body))
     (swap! *refs #(remove string/blank? %))
     (swap! *refs #(remove string/blank? %))
-    (let [ref->map-fn (fn [*col _tag?]
+    (let [*name->id (atom {})
+          ref->map-fn (fn [*col _tag?]
                         (let [col (remove string/blank? @*col)
                         (let [col (remove string/blank? @*col)
                               children-pages (->> (mapcat (fn [p]
                               children-pages (->> (mapcat (fn [p]
                                                             (let [p (if (map? p)
                                                             (let [p (if (map? p)
@@ -369,7 +370,14 @@
                              (let [macro? (and (map? item)
                              (let [macro? (and (map? item)
                                                (= "macro" (:type item)))]
                                                (= "macro" (:type item)))]
                                (when-not macro?
                                (when-not macro?
-                                 (page-name->map item with-id? db true date-formatter)))) col)))]
+                                 (let [result (page-name->map item with-id? db true date-formatter)
+                                       page-name (:block/name result)
+                                       id (get @*name->id page-name)]
+                                   (when (and with-id? (nil? id))
+                                     (swap! *name->id assoc page-name (:block/uuid result)))
+                                   (if id
+                                     (assoc result :block/uuid id)
+                                     result))))) col)))]
       (assoc block
       (assoc block
              :refs (ref->map-fn *refs false)
              :refs (ref->map-fn *refs false)
              :tags (ref->map-fn *structured-tags true)))))
              :tags (ref->map-fn *structured-tags true)))))

+ 28 - 9
deps/outliner/src/logseq/outliner/core.cljs

@@ -111,8 +111,9 @@
                              (ldb/get-orphaned-pages db {:pages old-pages
                              (ldb/get-orphaned-pages db {:pages old-pages
                                                          :empty-ref-f (fn [page]
                                                          :empty-ref-f (fn [page]
                                                                         (let [refs (:block/_refs page)]
                                                                         (let [refs (:block/_refs page)]
-                                                                          (or (zero? (count refs))
-                                                                              (= #{db-id} (set (map :db/id refs))))))}))]
+                                                                          (and (or (zero? (count refs))
+                                                                                   (= #{db-id} (set (map :db/id refs))))
+                                                                               (not (some #{"class" "property"} (:block/type page))))))}))]
         (when (seq orphaned-pages)
         (when (seq orphaned-pages)
           (let [tx (mapv (fn [page] [:db/retractEntity (:db/id page)]) orphaned-pages)]
           (let [tx (mapv (fn [page] [:db/retractEntity (:db/id page)]) orphaned-pages)]
             (swap! txs-state (fn [state] (vec (concat state tx))))))))))
             (swap! txs-state (fn [state] (vec (concat state tx))))))))))
@@ -245,12 +246,23 @@
   (when (sqlite-util/db-based-graph? repo)
   (when (sqlite-util/db-based-graph? repo)
     (let [refs (->> (rebuild-block-refs repo conn date-formatter block (:block/properties block))
     (let [refs (->> (rebuild-block-refs repo conn date-formatter block (:block/properties block))
                     (concat (:block/refs m))
                     (concat (:block/refs m))
-                    (concat (if (seq (:block/tags m))
-                              (:block/tags m)
-                              (map :db/id (:block/tags (d/entity @conn [:block/uuid (:block/uuid block)])))))
-                    (remove nil?))]
+                    (concat (:block/tags m))
+                    (remove nil?))
+          add-tag-type (map
+                        (fn [t]
+                          (cond
+                            (integer? t)
+                            {:db/id t
+                             :block/type "class"}
+                            (and (vector? t) (= (count t) 2) (= :block/uuid (first t)))
+                            {:block/uuid (second t)
+                             :block/type "class"}
+                            :else
+                            (throw (js/Error. (str "Wrong tag: " t)))))
+                        (:block/tags m))]
       (swap! txs-state (fn [txs] (concat txs [{:db/id (:db/id block)
       (swap! txs-state (fn [txs] (concat txs [{:db/id (:db/id block)
-                                               :block/refs refs}]))))))
+                                               :block/refs refs}]
+                                         add-tag-type))))))
 
 
 (defn- fix-tag-ids
 (defn- fix-tag-ids
   [m]
   [m]
@@ -367,7 +379,14 @@
           block-entity (d/entity db eid)
           block-entity (d/entity db eid)
           m (cond->> m
           m (cond->> m
               db-based?
               db-based?
-              (db-marker-handle conn))]
+              (db-marker-handle conn))
+          m (if db-based?
+              (update m :block/tags (fn [tags]
+                                      (->>
+                                       (concat (map :db/id (:block/tags block-entity))
+                                               (map (fn [t] (or (:db/id t) [:block/uuid (:block/uuid t)])) tags))
+                                       (remove nil?))))
+              m)]
 
 
       ;; Ensure block UUID never changes
       ;; Ensure block UUID never changes
       (let [e (d/entity db db-id)]
       (let [e (d/entity db db-id)]
@@ -381,7 +400,7 @@
         ;; Retract attributes to prepare for tx which rewrites block attributes
         ;; Retract attributes to prepare for tx which rewrites block attributes
         (when (:block/content m)
         (when (:block/content m)
           (let [retract-attributes (if db-based?
           (let [retract-attributes (if db-based?
-                                     db-schema/db-version-retract-attributes
+                                     (conj db-schema/db-version-retract-attributes :block/tags)
                                      db-schema/retract-attributes)]
                                      db-schema/retract-attributes)]
             (swap! txs-state (fn [txs]
             (swap! txs-state (fn [txs]
                                (vec
                                (vec

+ 4 - 9
src/main/frontend/components/block.cljs

@@ -2042,11 +2042,9 @@
          ;; highlight ref block (inline)
          ;; highlight ref block (inline)
          (when-not area? [(hl-ref)])
          (when-not area? [(hl-ref)])
 
 
-         (if title
-           (conj
-            (map-inline config title)
-            (when (= block-type :whiteboard-shape) [:span.mr-1 (ui/icon "whiteboard-element" {:extension? true})]))
-           [[:span.opacity-50 "Click here to start writing, type '/' to see all the commands."]])
+         (conj
+          (map-inline config title)
+          (when (= block-type :whiteboard-shape) [:span.mr-1 (ui/icon "whiteboard-element" {:extension? true})]))
 
 
          ;; highlight ref block (area)
          ;; highlight ref block (area)
          (when area? [(hl-ref)])))))))
          (when area? [(hl-ref)])))))))
@@ -2420,11 +2418,8 @@
                 (icon/get-page-icon block {})
                 (icon/get-page-icon block {})
                 (page-cp config block)]
                 (page-cp config block)]
 
 
-               (or (seq title) (:block/marker block))
-               (build-block-title config block)
-
                :else
                :else
-               nil)
+               (build-block-title config block))
 
 
              [:div.flex.flex-row.items-center.gap-1
              [:div.flex.flex-row.items-center.gap-1
               (when (and db-based? (seq block-tags))
               (when (and db-based? (seq block-tags))

+ 3 - 7
src/main/frontend/handler/db_based/editor.cljs

@@ -71,7 +71,7 @@
     (assoc block :block/content content')))
     (assoc block :block/content content')))
 
 
 (defn wrap-parse-block
 (defn wrap-parse-block
-  [{:block/keys [content left level tags] :as block}]
+  [{:block/keys [content left level] :as block}]
   (let [block (or (and (:db/id block) (db/pull (:db/id block))) block)
   (let [block (or (and (:db/id block) (db/pull (:db/id block))) block)
         block (if (nil? content)
         block (if (nil? content)
                 block
                 block
@@ -98,12 +98,8 @@
                   (fn [tag]
                   (fn [tag]
                     (when (:block/uuid tag)
                     (when (:block/uuid tag)
                       (str db-content/page-ref-special-chars (:block/uuid tag))))
                       (str db-content/page-ref-special-chars (:block/uuid tag))))
-                  (:block/tags result))
-                 (remove nil?))))
-        ;; Remove :block/tags built from mldoc
-        (dissoc :block/tags)
-        ;; Add tags back
-        (assoc :block/tags tags))))
+                  (concat (:block/tags result) (:block/tags block)))
+                 (remove nil?)))))))
 
 
 (defn save-file!
 (defn save-file!
   "This fn is the db version of file-handler/alter-file"
   "This fn is the db version of file-handler/alter-file"

+ 5 - 1
src/main/frontend/handler/editor.cljs

@@ -1863,7 +1863,11 @@
     (reset! *auto-save-timeout
     (reset! *auto-save-timeout
             (js/setTimeout
             (js/setTimeout
              (fn []
              (fn []
-               (when (state/input-idle? repo :diff 450)
+               (when (and (state/input-idle? repo :diff 450)
+                          ;; don't auto-save block if it has tags
+                          (not (and
+                                (config/db-based-graph? repo)
+                                (re-find #"#\S+" value))))
                  ; don't auto-save for page's properties block
                  ; don't auto-save for page's properties block
                  (save-current-block! {:skip-properties? true})))
                  (save-current-block! {:skip-properties? true})))
              450))))
              450))))