mirror of
https://github.com/logseq/logseq.git
synced 2026-05-03 02:16:30 +00:00
refactor: rearrange cycle-marker (#4661)
* refactor: rearrange cycle-marker Signed-off-by: Yue Yang <g1enyy0ung@gmail.com> * fix: remove unused markdown? Signed-off-by: Yue Yang <g1enyy0ung@gmail.com> * fix: marker-switch Signed-off-by: Yue Yang <g1enyy0ung@gmail.com> * fix: add missing arg Signed-off-by: Yue Yang <g1enyy0ung@gmail.com> * docs: cycle-marker and set-marker Signed-off-by: Yue Yang <g1enyy0ung@gmail.com> * chore: address comments Signed-off-by: Yue Yang <g1enyy0ung@gmail.com> * chore: format code Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>
This commit is contained in:
@@ -789,21 +789,6 @@
|
||||
(state/set-edit-content! input-id new-content)
|
||||
(save-block-if-changed! block new-content))))
|
||||
|
||||
(defn set-marker
|
||||
[{:block/keys [marker content format] :as block} new-marker]
|
||||
(let [old-header-marker (when (not= format :org)
|
||||
(re-find (marker/header-marker-pattern true marker) content))
|
||||
new-header-marker (when (not-empty old-header-marker)
|
||||
(string/replace old-header-marker marker new-marker))
|
||||
marker (or old-header-marker marker)
|
||||
new-marker (or new-header-marker new-marker)
|
||||
new-content (->
|
||||
(if (not-empty marker)
|
||||
(string/replace-first content (re-pattern (str "^" marker)) new-marker)
|
||||
(str new-marker " " content))
|
||||
(string/triml))]
|
||||
(save-block-if-changed! block new-content)))
|
||||
|
||||
(defn- rehighlight-selected-nodes
|
||||
([]
|
||||
(rehighlight-selected-nodes (state/get-selection-blocks)))
|
||||
@@ -827,18 +812,24 @@
|
||||
blocks)
|
||||
distinct)))
|
||||
|
||||
(defn set-marker
|
||||
"The set-marker will set a new marker on the selected block.
|
||||
if the `new-marker` is nil, it will generate it automatically."
|
||||
([block]
|
||||
(set-marker block nil))
|
||||
([{:block/keys [marker content format] :as block} new-marker]
|
||||
(let [[new-content _] (marker/cycle-marker content marker new-marker format (state/get-preferred-workflow))]
|
||||
(save-block-if-changed! block new-content))))
|
||||
|
||||
(defn cycle-todos!
|
||||
[]
|
||||
(when-let [blocks (seq (get-selected-blocks-with-children))]
|
||||
(let [workflow (state/get-preferred-workflow)
|
||||
ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
|
||||
(let [ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
|
||||
(uuid id)) blocks))
|
||||
(remove nil?))]
|
||||
(doseq [id ids]
|
||||
(let [block (db/pull [:block/uuid id])
|
||||
new-marker (marker/cycle-marker-state workflow (:block/marker block))
|
||||
new-marker (if new-marker new-marker "")]
|
||||
(set-marker block new-marker)))
|
||||
(let [block (db/pull [:block/uuid id])]
|
||||
(set-marker block)))
|
||||
(js/setTimeout #(rehighlight-selected-nodes blocks) 0))))
|
||||
|
||||
(defn cycle-todo!
|
||||
@@ -852,8 +843,7 @@
|
||||
content (state/get-edit-content)
|
||||
format (or (db/get-page-format (state/get-current-page))
|
||||
(state/get-preferred-format))
|
||||
[new-content marker] (marker/cycle-marker content format (state/get-preferred-workflow))
|
||||
new-content (string/triml new-content)
|
||||
[new-content marker] (marker/cycle-marker content nil nil format (state/get-preferred-workflow))
|
||||
new-pos (commands/compute-pos-delta-when-change-marker
|
||||
content marker (cursor/pos current-input))]
|
||||
(state/set-edit-content! edit-input-id new-content)
|
||||
|
||||
Reference in New Issue
Block a user