mirror of https://github.com/logseq/logseq
enhance: bring back inline tags support
parent
38f20be9fc
commit
caf1af1911
|
@ -12,11 +12,10 @@
|
|||
(re-pattern
|
||||
(str
|
||||
"(?i)"
|
||||
"\\[\\[~\\^"
|
||||
"~\\^"
|
||||
"("
|
||||
common-util/uuid-pattern
|
||||
")"
|
||||
"\\]\\]")))
|
||||
")")))
|
||||
|
||||
(defn special-id-ref->page
|
||||
"Convert special id ref backs to page name using refs."
|
||||
|
@ -24,12 +23,16 @@
|
|||
(reduce
|
||||
(fn [content ref]
|
||||
(if (:block/name ref)
|
||||
(string/replace content
|
||||
(str page-ref/left-brackets
|
||||
page-ref-special-chars
|
||||
(:block/uuid ref)
|
||||
page-ref/right-brackets)
|
||||
(:block/original-name ref))
|
||||
(-> content
|
||||
(string/replace (str page-ref/left-brackets
|
||||
page-ref-special-chars
|
||||
(:block/uuid ref)
|
||||
page-ref/right-brackets)
|
||||
(:block/original-name ref))
|
||||
(string/replace
|
||||
(str "#" page-ref-special-chars
|
||||
(:block/uuid ref))
|
||||
(str "#" (:block/original-name ref))))
|
||||
content))
|
||||
content
|
||||
refs))
|
||||
|
@ -38,16 +41,25 @@
|
|||
"Convert special id ref backs to page name refs using refs."
|
||||
[content* refs]
|
||||
(let [content (str content*)]
|
||||
(if (string/includes? content (str page-ref/left-brackets page-ref-special-chars))
|
||||
(if (or (string/includes? content (str page-ref/left-brackets page-ref-special-chars))
|
||||
(string/includes? content (str "#" page-ref-special-chars)))
|
||||
(reduce
|
||||
(fn [content ref]
|
||||
(if (:block/name ref)
|
||||
(string/replace content
|
||||
(str page-ref/left-brackets
|
||||
page-ref-special-chars
|
||||
(:block/uuid ref)
|
||||
page-ref/right-brackets)
|
||||
(page-ref/->page-ref (:block/original-name ref)))
|
||||
(-> content
|
||||
;; Replace page refs
|
||||
(string/replace
|
||||
(str page-ref/left-brackets
|
||||
page-ref-special-chars
|
||||
(:block/uuid ref)
|
||||
page-ref/right-brackets)
|
||||
(page-ref/->page-ref (:block/original-name ref)))
|
||||
;; Replace tags
|
||||
(string/replace
|
||||
(str "#" page-ref-special-chars
|
||||
(:block/uuid ref))
|
||||
(str "#" (:block/original-name ref))))
|
||||
|
||||
content))
|
||||
content
|
||||
refs)
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
[logseq.db.sqlite.create-graph :as sqlite-create-graph]
|
||||
[logseq.outliner.batch-tx :include-macros true :as batch-tx]
|
||||
[logseq.db.frontend.order :as db-order]
|
||||
[logseq.outliner.pipeline :as outliner-pipeline]
|
||||
[logseq.db.frontend.class :as db-class]))
|
||||
[logseq.outliner.pipeline :as outliner-pipeline]))
|
||||
|
||||
(def ^:private block-map
|
||||
(mu/optional-keys
|
||||
|
@ -205,20 +204,6 @@
|
|||
(outliner-pipeline/db-rebuild-block-refs db block)
|
||||
(file-rebuild-block-refs repo db date-formatter block)))
|
||||
|
||||
(defn- add-tag-types
|
||||
[repo db txs-state new-tags]
|
||||
(when (sqlite-util/db-based-graph? repo)
|
||||
(let [add-tag-type (keep
|
||||
(fn [t]
|
||||
(let [eid (outliner-pipeline/ref->eid t)]
|
||||
(when (and (:block/original-name t) eid)
|
||||
(db-class/build-new-class
|
||||
db
|
||||
{:db/id eid
|
||||
:block/original-name (:block/original-name t)}))))
|
||||
new-tags)]
|
||||
(swap! txs-state (fn [txs] (concat txs add-tag-type))))))
|
||||
|
||||
(defn- fix-tag-ids
|
||||
"Updates :block/tags to reference ids from :block/refs"
|
||||
[m]
|
||||
|
@ -251,14 +236,15 @@
|
|||
data)
|
||||
db-based?
|
||||
(dissoc :block/properties))
|
||||
;; new tags are needed in their original form before being altered
|
||||
new-tags (:block/tags data')
|
||||
m* (-> data'
|
||||
(dissoc :block/children :block/meta :block.temp/top? :block.temp/bottom? :block/unordered
|
||||
:block/title :block/body :block/level :block.temp/fully-loaded?)
|
||||
common-util/remove-nils
|
||||
block-with-updated-at
|
||||
fix-tag-ids)
|
||||
m* (if db-based?
|
||||
(dissoc m* :block/tags)
|
||||
m*)
|
||||
db @conn
|
||||
db-id (:db/id this)
|
||||
block-uuid (:block/uuid this)
|
||||
|
@ -266,11 +252,7 @@
|
|||
block-entity (d/entity db eid)
|
||||
m (cond-> m*
|
||||
db-based?
|
||||
(dissoc :block/priority :block/marker :block/properties-order)
|
||||
db-based?
|
||||
(update :block/tags (fn [tags]
|
||||
(concat (keep :db/id (:block/tags block-entity))
|
||||
(keep outliner-pipeline/ref->eid tags)))))]
|
||||
(dissoc :block/priority :block/marker :block/properties-order))]
|
||||
;; Ensure block UUID never changes
|
||||
(let [e (d/entity db db-id)]
|
||||
(when (and e block-uuid)
|
||||
|
@ -285,7 +267,7 @@
|
|||
(seq retract-attributes))
|
||||
(let [retract-attributes (concat
|
||||
(if db-based?
|
||||
(conj db-schema/db-version-retract-attributes :block/tags)
|
||||
db-schema/db-version-retract-attributes
|
||||
db-schema/retract-attributes)
|
||||
retract-attributes)]
|
||||
(swap! txs-state (fn [txs]
|
||||
|
@ -309,8 +291,6 @@
|
|||
(swap! txs-state conj
|
||||
(dissoc m :db/other-tx)))
|
||||
|
||||
(add-tag-types repo db txs-state new-tags)
|
||||
|
||||
;; delete heading property for db-based-graphs
|
||||
(when (and db-based? (integer? (:logseq.property/heading block-entity))
|
||||
(not (some-> (:block/content data) (string/starts-with? "#"))))
|
||||
|
|
|
@ -2323,10 +2323,13 @@
|
|||
[config {:block/keys [uuid content properties scheduled deadline format pre-block?] :as block} edit-input-id block-id slide?]
|
||||
(let [repo (state/get-current-repo)
|
||||
content (or (:block/original-name block)
|
||||
(property-util/remove-built-in-properties format content))
|
||||
(if (config/db-based-graph? (state/get-current-repo))
|
||||
(:block/content block)
|
||||
(property-util/remove-built-in-properties format content)))
|
||||
{:block/keys [title body] :as block} (if (:block/title block) block
|
||||
(merge block (block/parse-title-and-body uuid format pre-block? content)))
|
||||
collapsed? (util/collapsed? block)
|
||||
block (assoc block :block/content content)
|
||||
plugin-slotted? (and config/lsp-enabled? (state/slot-hook-exist? uuid))
|
||||
block-ref? (:block-ref? config)
|
||||
stop-events? (:stop-events? config)
|
||||
|
@ -2883,7 +2886,7 @@
|
|||
custom-query? (boolean (:custom-query? config*))
|
||||
ref-or-custom-query? (or ref? custom-query?)
|
||||
*navigating-block (get container-state ::navigating-block)
|
||||
{:block/keys [uuid pre-block? raw-content content]} block
|
||||
{:block/keys [uuid pre-block? content]} block
|
||||
config (build-config config* block {:navigated? navigated? :navigating-block navigating-block})
|
||||
level (:level config)
|
||||
*control-show? (get container-state ::control-show?)
|
||||
|
@ -2982,9 +2985,9 @@
|
|||
|
||||
(if whiteboard-block?
|
||||
(block-reference {} (str uuid) nil)
|
||||
;; Not embed self
|
||||
;; Not embed self
|
||||
[:div.flex.flex-col.w-full
|
||||
(let [block (merge block (block/parse-title-and-body uuid (:block/format block) pre-block? (or raw-content content)))
|
||||
(let [block (merge block (block/parse-title-and-body uuid (:block/format block) pre-block? content))
|
||||
hide-block-refs-count? (and (:embed? config)
|
||||
(= (:block/uuid block) (:embed-id config)))]
|
||||
(block-content-or-editor config block
|
||||
|
|
|
@ -132,9 +132,7 @@
|
|||
(let [[matched-pages set-matched-pages!] (rum/use-state nil)]
|
||||
(rum/use-effect! (fn []
|
||||
(when-not (string/blank? q)
|
||||
(p/let [result (if db-tag?
|
||||
(editor-handler/get-matched-classes q)
|
||||
(editor-handler/<get-matched-pages q))]
|
||||
(p/let [result (editor-handler/<get-matched-pages q)]
|
||||
(set-matched-pages! result))))
|
||||
[q])
|
||||
(let [matched-pages (cond
|
||||
|
@ -150,9 +148,11 @@
|
|||
(empty? matched-pages)
|
||||
(when-not (db/page-exists? q)
|
||||
(if db-tag?
|
||||
(concat [(str (t :new-class) " " q)]
|
||||
(concat [(str (t :new-page) " " q)
|
||||
(str (t :new-class) " " q)]
|
||||
matched-pages)
|
||||
(cons q matched-pages)))
|
||||
(cons (str (t :new-page) " " q)
|
||||
matched-pages)))
|
||||
|
||||
;; reorder, shortest and starts-with first.
|
||||
:else
|
||||
|
|
|
@ -102,7 +102,7 @@
|
|||
(fn [tag]
|
||||
(when (:block/uuid tag)
|
||||
(str db-content/page-ref-special-chars (:block/uuid tag))))
|
||||
(concat (:block/tags result) (:block/tags block)))
|
||||
(:block/tags (db/entity (:db/id block))))
|
||||
(remove nil?)))))))
|
||||
|
||||
(defn save-file!
|
||||
|
|
|
@ -1645,12 +1645,13 @@
|
|||
pages)
|
||||
(map :title))))
|
||||
|
||||
(defn get-matched-classes
|
||||
"Return matched class names"
|
||||
[q]
|
||||
(let [classes (->> (db-model/get-all-classes (state/get-current-repo))
|
||||
(map first))]
|
||||
(search/fuzzy-search classes q {:limit 100})))
|
||||
(comment
|
||||
(defn get-matched-classes
|
||||
"Return matched class names"
|
||||
[q]
|
||||
(let [classes (->> (db-model/get-all-classes (state/get-current-repo))
|
||||
(map first))]
|
||||
(search/fuzzy-search classes q {:limit 100}))))
|
||||
|
||||
(defn get-matched-blocks
|
||||
[q block-id]
|
||||
|
|
|
@ -336,7 +336,9 @@
|
|||
(fn [chosen e]
|
||||
(util/stop e)
|
||||
(state/clear-editor-action!)
|
||||
(let [class? (and db-based? hashtag?)
|
||||
(let [class? (and db-based? hashtag?
|
||||
(or (string/includes? chosen (str (t :new-class) " "))
|
||||
(ldb/class? (db/get-page chosen))))
|
||||
chosen (-> chosen
|
||||
(string/replace-first (str (t :new-class) " ") "")
|
||||
(string/replace-first (str (t :new-page) " ") ""))
|
||||
|
@ -378,7 +380,8 @@
|
|||
(fn [chosen e]
|
||||
(util/stop e)
|
||||
(state/clear-editor-action!)
|
||||
(let [page-ref-text (get-page-ref-text chosen)]
|
||||
(let [chosen' (string/replace-first chosen (str (t :new-page) " ") "")
|
||||
page-ref-text (get-page-ref-text chosen')]
|
||||
(editor-handler/insert-command! id
|
||||
page-ref-text
|
||||
format
|
||||
|
|
Loading…
Reference in New Issue