Merge branch 'feat/outliner-core' of github.com:logseq/logseq into feat/outliner-core

This commit is contained in:
Tienson Qin
2021-05-08 19:36:49 +08:00
4 changed files with 41 additions and 17 deletions

View File

@@ -419,7 +419,7 @@
(defn compute-pos-delta-when-change-marker
[current-input edit-content new-value marker pos]
(let [old-marker (some->> (first (re-find format/bare-marker-pattern edit-content))
(let [old-marker (some->> (first (re-find util/bare-marker-pattern edit-content))
(string/trim))
old-marker (if old-marker old-marker "")
pos-delta (- (count marker)
@@ -444,7 +444,7 @@
(count (re-find re-pattern prefix))))
new-value (str (subs edit-content 0 pos)
(string/replace-first (subs edit-content pos)
format/marker-pattern
util/marker-pattern
(str marker " ")))]
(state/set-edit-content! input-id new-value)
(let [new-pos (compute-pos-delta-when-change-marker
@@ -467,8 +467,8 @@
(string/replace-first (subs edit-content pos)
priority-pattern
new-priority))
(re-find format/marker-pattern edit-content)
(string/replace-first edit-content format/marker-pattern
(re-find util/marker-pattern edit-content)
(string/replace-first edit-content util/marker-pattern
(fn [marker] (str marker new-priority " ")))
:else

View File

@@ -64,9 +64,3 @@
[format]
(when-let [record (get-format-record format)]
(protocol/loaded? record)))
(def marker-pattern
#"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS)?\s?")
(def bare-marker-pattern
#"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS){1}\s+")

View File

@@ -506,7 +506,7 @@
(defn- with-timetracking-properties
[block value]
(let [new-marker (first (re-find format/bare-marker-pattern (or value "")))
(let [new-marker (first (re-find util/bare-marker-pattern (or value "")))
new-marker (if new-marker (string/lower-case (string/trim new-marker)))
time-properties (if (and
new-marker
@@ -594,28 +594,34 @@
(let [edit-input-id (state/get-edit-input-id)
current-input (gdom/getElement edit-input-id)
content (state/get-edit-content)
format (or (db/get-page-format (state/get-current-page))
(state/get-preferred-format))
cond-fn (fn [marker] (or (and (= :markdown format)
(re-find (re-pattern (str "#*\\s*" marker)) content))
(util/starts-with? content "TODO")))
[new-content marker] (cond
(util/starts-with? content "TODO")
(cond-fn "TODO")
[(string/replace-first content "TODO" "DOING") "DOING"]
(util/starts-with? content "DOING")
(cond-fn "DOING")
[(string/replace-first content "DOING" "DONE") "DONE"]
(util/starts-with? content "LATER")
(cond-fn "LATER")
[(string/replace-first content "LATER" "NOW") "NOW"]
(util/starts-with? content "NOW")
(cond-fn "NOW")
[(string/replace-first content "NOW" "DONE") "DONE"]
(util/starts-with? content "DONE")
(cond-fn "DONE")
[(string/replace-first content "DONE" "") nil]
:else
(let [marker (if (= :now (state/get-preferred-workflow))
"LATER"
"TODO")]
[(str marker " " (string/triml content)) marker]))
[(util/add-or-update-marker (string/triml content) format marker) marker]))
new-content (string/triml new-content)]
(let [new-pos (commands/compute-pos-delta-when-change-marker
current-input content new-content marker (util/get-input-pos current-input))]
(state/set-edit-content! edit-input-id new-content)
(util/set-caret-pos! current-input new-pos)))))
(defn set-marker
[{:block/keys [uuid marker content dummy? properties] :as block} new-marker]
(let [new-content (string/replace-first content marker new-marker)]

View File

@@ -1008,6 +1008,30 @@
"DONE" "WAIT" "WAITING" "CANCELED" "CANCELLED" "STARTED" "IN-PROGRESS"}
(string/upper-case s)))
(def marker-pattern
#"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS)?\s?")
(def bare-marker-pattern
#"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS){1}\s+")
(defn add-or-update-marker
[content format marker]
(let [[re-pattern new-line-re-pattern]
(if (= :org format)
[#"\*+\s" #"\n\*+\s"]
[#"#+\s" #"\n#+\s"])
pos
(if-let [matches (seq (re-pos new-line-re-pattern content))]
(let [[start-pos content] (last matches)]
(+ start-pos (count content)))
(count (re-find re-pattern content)))
new-content
(str (subs content 0 pos)
(string/replace-first (subs content pos)
marker-pattern
(str marker " ")))]
new-content))
(defn pp-str [x]
(with-out-str (clojure.pprint/pprint x)))