fix: inline namespace tag editing

pull/11517/head
Tienson Qin 2024-09-15 11:57:53 +08:00
parent b1a9e9ae30
commit a47608e953
7 changed files with 34 additions and 25 deletions

View File

@ -252,13 +252,16 @@
(d/entity db)))
(defn ^:api split-namespace-pages
[db page-or-pages date-formatter & {:keys [*changed-uuids]}]
(let [pages (if (map? page-or-pages) [page-or-pages] page-or-pages)]
[db page-or-pages tags date-formatter & {:keys [*changed-uuids]}]
(let [pages (if (map? page-or-pages) [page-or-pages] page-or-pages)
tags-set (set (map :block/uuid tags))]
(->>
(mapcat
(fn [{:block/keys [title] :as page}]
(let [block-uuid (:block/uuid page)
block-type (:block/type page)]
block-type (if (contains? tags-set (:block/uuid page))
"class"
(:block/type page))]
(if (and (contains? #{"page" "class"} block-type) (text/namespace-page? title))
(let [class? (= block-type "class")
parts (->> (string/split title #"/")
@ -305,10 +308,15 @@
(remove nil?))))
(defn- build-page-parents
[db refs date-formatter raw-title]
(let [*changed-uuids (atom {})
refs' (split-namespace-pages db refs date-formatter
[db m date-formatter raw-title]
(let [refs (:block/refs m)
tags (:block/tags m)
*changed-uuids (atom {})
refs' (split-namespace-pages db refs tags date-formatter
{:*changed-uuids *changed-uuids})
tags' (map (fn [tag]
(or (first (filter (fn [ref] (= (:block/uuid ref) (:block/uuid tag))) refs')) tag))
tags)
raw-title' (if (seq @*changed-uuids)
(reduce
(fn [raw-content [old-id new-id]]
@ -316,8 +324,10 @@
raw-title
@*changed-uuids)
raw-title)]
{:refs refs'
:raw-title raw-title'}))
(assoc m
:block/refs refs'
:block/title raw-title'
:block/tags tags')))
(extend-type Entity
otree/INode
@ -367,8 +377,7 @@
db-based?
(dissoc :block/pre-block? :block/priority :block/marker :block/properties-order))
m (if db-based?
(let [{:keys [refs raw-title]} (build-page-parents db (:block/refs m) date-formatter (:block/title m))]
(assoc m :block/refs refs :block/title raw-title))
(build-page-parents db m date-formatter (:block/title m))
m)]
;; Ensure block UUID never changes
(let [e (d/entity db db-id)]

View File

@ -2255,7 +2255,7 @@
{:on-pointer-down (fn [e]
(util/stop e)
(state/clear-editor-action!)
(editor-handler/escape-editing false)
(editor-handler/escape-editing)
(reset! *show-datapicker? true)
(reset! commands/*current-command typ)
(state/set-timestamp-block! {:block block

View File

@ -727,7 +727,8 @@
(dom/remove-class! container "blocks-selection-mode"))
(p/do!
(editor-handler/save-block! repo (:block/uuid block) value)
(editor-handler/escape-editing select?)
(editor-handler/escape-editing {:select? select?
:save-block? false})
(some-> config :on-escape-editing
(apply [(str uuid) (= type :esc)])))))))

View File

@ -3756,15 +3756,14 @@
(select-all-blocks! {})))))))
(defn escape-editing
([]
(escape-editing true))
([select?]
(p/do!
(save-current-block!)
(if select?
(when-let [node (some-> (state/get-input) (util/rec-get-node "ls-block"))]
(state/exit-editing-and-set-selected-blocks! [node]))
(state/clear-edit!)))))
[& {:keys [select? save-block?]
:or {save-block? true}}]
(p/do!
(when save-block? (save-current-block!))
(if select?
(when-let [node (some-> (state/get-input) (util/rec-get-node "ls-block"))]
(state/exit-editing-and-set-selected-blocks! [node]))
(state/clear-edit!))))
(defn replace-block-reference-with-content-at-point
[]

View File

@ -32,7 +32,7 @@
(defn- search
[mode]
(editor-handler/escape-editing true)
(editor-handler/escape-editing {:select? true})
(if (state/get-search-mode)
(js/setTimeout #(route-handler/go-to-search! mode) 128)
(route-handler/go-to-search! mode)))
@ -462,7 +462,7 @@
:command/run {:binding "mod+shift+1"
:inactive (not (util/electron?))
:fn #(do
(editor-handler/escape-editing true)
(editor-handler/escape-editing {:select? true})
(state/pub-event! [:command/run]))}
:go/home {:binding "g h"

View File

@ -95,7 +95,7 @@
:skip-existing-page-check? true})
(assoc :block/format format))
[page parents] (if (and (text/namespace-page? title) split-namespace?)
(let [pages (outliner-core/split-namespace-pages db page date-formatter)]
(let [pages (outliner-core/split-namespace-pages db page nil date-formatter)]
[(last pages) (butlast pages)])
[page nil])]
(when page

View File

@ -543,7 +543,7 @@
(def ^:export exit_editing_mode
(fn [select?]
(editor-handler/escape-editing select?)
(editor-handler/escape-editing {:select? select?})
nil))
(def ^:export insert_at_editing_cursor