fix(timestamp): remove old SCHEDULED/DEADLINE timestamp

When using `date-picker` to update the SCHEDULED/DEADLINE timestamp by
clicking an existing one, logseq will add a new timestamp instead of
updating the old one. This patch fixs this issue.
This commit is contained in:
leizhe
2021-09-04 12:59:09 +09:00
committed by Tienson Qin
parent cb23b967e4
commit 1f2c9e4d3f
2 changed files with 12 additions and 1 deletions

View File

@@ -1006,7 +1006,8 @@
(when-let [block (db/pull [:block/uuid block-id])]
(let [{:block/keys [content scheduled deadline format]} block
content (or (state/get-edit-content) content)
new-content (text/add-timestamp content key value)]
new-content (-> (text/remove-timestamp content key)
(text/add-timestamp key value))]
(when (not= content new-content)
(if-let [input-id (state/get-edit-input-id)]
(state/set-edit-content! input-id new-content)

View File

@@ -240,3 +240,13 @@
new-line
(rest new-lines))))]
(string/join "\n" new-lines)))
(defn remove-timestamp
[content key]
(let [lines (string/split-lines content)
new-lines (filter (fn [line]
(not (string/starts-with? (string/lower-case line) key)))
lines)]
(println "new-lines" new-lines)
(string/join "\n" new-lines)))