refactor: unify :editor/show-xxx and (block) commands to :editor/action

This commit is contained in:
Tienson Qin
2022-07-06 20:01:14 +08:00
parent 92f2a2bba1
commit 6d0be829a1
7 changed files with 279 additions and 284 deletions

View File

@@ -691,15 +691,17 @@
[input id _q pos format]
(let [current-pos (cursor/pos input)
edit-content (state/sub [:editor/content id])
action (state/get-editor-action)
hashtag? (= action :page-search-hashtag)
q (or
@editor-handler/*selected-text
(when (state/sub :editor/show-page-search-hashtag?)
(when hashtag?
(gp-util/safe-subs edit-content pos current-pos))
(when (> (count edit-content) current-pos)
(gp-util/safe-subs edit-content pos current-pos)))]
(if (state/sub :editor/show-page-search-hashtag?)
(if hashtag?
(fn [chosen _click?]
(state/set-editor-show-page-search! false)
(state/clear-editor-action!)
(let [wrapped? (= "[[" (gp-util/safe-subs edit-content (- pos 2) pos))
chosen (if (string/starts-with? chosen "New page: ") ;; FIXME: What if a page named "New page: XXX"?
(subs chosen 10)
@@ -721,7 +723,7 @@
:end-pattern (when wrapped? "]]")
:forward-pos forward-pos})))
(fn [chosen _click?]
(state/set-editor-show-page-search! false)
(state/clear-editor-action!)
(let [chosen (if (string/starts-with? chosen "New page: ")
(subs chosen 10)
chosen)