mirror of https://github.com/logseq/logseq
fix: suggestions from gabriel
parent
e8023b9246
commit
139075e679
|
@ -605,22 +605,22 @@
|
||||||
(state/set-edit-content! input-id new-value)))))
|
(state/set-edit-content! input-id new-value)))))
|
||||||
|
|
||||||
(defmethod handle-step :editor/search-page [[_]]
|
(defmethod handle-step :editor/search-page [[_]]
|
||||||
(state/set-editor-show-page-search! true))
|
(state/set-editor-action! :page-search))
|
||||||
|
|
||||||
(defmethod handle-step :editor/search-page-hashtag [[_]]
|
(defmethod handle-step :editor/search-page-hashtag [[_]]
|
||||||
(state/set-editor-show-page-search-hashtag! true))
|
(state/set-editor-action! :page-search-hashtag))
|
||||||
|
|
||||||
(defmethod handle-step :editor/search-block [[_ _type]]
|
(defmethod handle-step :editor/search-block [[_ _type]]
|
||||||
(state/set-editor-show-block-search! true))
|
(state/set-editor-action! :block-search))
|
||||||
|
|
||||||
(defmethod handle-step :editor/search-template [[_]]
|
(defmethod handle-step :editor/search-template [[_]]
|
||||||
(state/set-editor-show-template-search! true))
|
(state/set-editor-action! :template-search))
|
||||||
|
|
||||||
(defmethod handle-step :editor/show-input [[_ option]]
|
(defmethod handle-step :editor/show-input [[_ option]]
|
||||||
(state/set-editor-show-input! option))
|
(state/set-editor-show-input! option))
|
||||||
|
|
||||||
(defmethod handle-step :editor/show-zotero [[_]]
|
(defmethod handle-step :editor/show-zotero [[_]]
|
||||||
(state/set-editor-show-zotero! true))
|
(state/set-editor-action! :zotero))
|
||||||
|
|
||||||
(defn insert-youtube-timestamp
|
(defn insert-youtube-timestamp
|
||||||
[]
|
[]
|
||||||
|
@ -643,7 +643,7 @@
|
||||||
(do
|
(do
|
||||||
(notification/show! [:div "Please add some content first."] :warning)
|
(notification/show! [:div "Please add some content first."] :warning)
|
||||||
(restore-state))
|
(restore-state))
|
||||||
(state/set-editor-show-date-picker! true)))
|
(state/set-editor-action! :datepicker)))
|
||||||
|
|
||||||
(defmethod handle-step :editor/click-hidden-file-input [[_ _input-id]]
|
(defmethod handle-step :editor/click-hidden-file-input [[_ _input-id]]
|
||||||
(when-let [input-file (gdom/getElement "upload-file")]
|
(when-let [input-file (gdom/getElement "upload-file")]
|
||||||
|
|
|
@ -1896,12 +1896,12 @@
|
||||||
(do
|
(do
|
||||||
(reset! show? false)
|
(reset! show? false)
|
||||||
(reset! commands/*current-command nil)
|
(reset! commands/*current-command nil)
|
||||||
(state/set-editor-show-date-picker! false)
|
(state/clear-editor-action!)
|
||||||
(state/set-timestamp-block! nil))
|
(state/set-timestamp-block! nil))
|
||||||
(do
|
(do
|
||||||
(reset! show? true)
|
(reset! show? true)
|
||||||
(reset! commands/*current-command typ)
|
(reset! commands/*current-command typ)
|
||||||
(state/set-editor-show-date-picker! true)
|
(state/set-editor-action! :datepicker)
|
||||||
(state/set-timestamp-block! {:block block
|
(state/set-timestamp-block! {:block block
|
||||||
:typ typ
|
:typ typ
|
||||||
:show? show?}))))}
|
:show? show?}))))}
|
||||||
|
|
|
@ -105,7 +105,6 @@
|
||||||
(when show?
|
(when show?
|
||||||
(reset! show? false)))
|
(reset! show? false)))
|
||||||
(clear-timestamp!)
|
(clear-timestamp!)
|
||||||
(state/set-editor-show-date-picker! false)
|
|
||||||
(commands/restore-state))
|
(commands/restore-state))
|
||||||
|
|
||||||
(rum/defc time-repeater < rum/reactive
|
(rum/defc time-repeater < rum/reactive
|
||||||
|
@ -164,7 +163,7 @@
|
||||||
(util/format "[[%s]]" journal)
|
(util/format "[[%s]]" journal)
|
||||||
format
|
format
|
||||||
nil)
|
nil)
|
||||||
(state/set-editor-show-date-picker! false)
|
(state/clear-editor-action!)
|
||||||
(reset! commands/*current-command nil))))})
|
(reset! commands/*current-command nil))))})
|
||||||
(when deadline-or-schedule?
|
(when deadline-or-schedule?
|
||||||
(time-repeater))])))
|
(time-repeater))])))
|
||||||
|
|
|
@ -219,7 +219,7 @@
|
||||||
"")
|
"")
|
||||||
matched-templates (editor-handler/get-matched-templates q)
|
matched-templates (editor-handler/get-matched-templates q)
|
||||||
non-exist-handler (fn [_state]
|
non-exist-handler (fn [_state]
|
||||||
(state/set-editor-show-template-search! false))]
|
(state/clear-editor-action!))]
|
||||||
(ui/auto-complete
|
(ui/auto-complete
|
||||||
matched-templates
|
matched-templates
|
||||||
{:on-chosen (editor-handler/template-on-chosen-handler id)
|
{:on-chosen (editor-handler/template-on-chosen-handler id)
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
(defn handle-command-zotero
|
(defn handle-command-zotero
|
||||||
[id page-name]
|
[id page-name]
|
||||||
(state/set-editor-show-zotero! false)
|
(state/clear-editor-action!)
|
||||||
(editor-handler/insert-command! id (str "[[" page-name "]]") nil {}))
|
(editor-handler/insert-command! id (str "[[" page-name "]]") nil {}))
|
||||||
|
|
||||||
(defn- create-abstract-note!
|
(defn- create-abstract-note!
|
||||||
|
|
|
@ -1848,7 +1848,7 @@
|
||||||
(do
|
(do
|
||||||
(cursor/move-cursor-backward input 2)
|
(cursor/move-cursor-backward input 2)
|
||||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
|
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
|
||||||
(state/set-editor-show-property-search! true))
|
(state/set-editor-action! :property-search))
|
||||||
|
|
||||||
(and
|
(and
|
||||||
(not= :property-search (state/get-editor-action))
|
(not= :property-search (state/get-editor-action))
|
||||||
|
@ -1856,7 +1856,7 @@
|
||||||
(wrapped-by? input "\n" "::")))
|
(wrapped-by? input "\n" "::")))
|
||||||
(do
|
(do
|
||||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
|
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
|
||||||
(state/set-editor-show-property-search! true))
|
(state/set-editor-action! :property-search))
|
||||||
|
|
||||||
(and (= last-input-char commands/colon) (= :property-search (state/get-editor-action)))
|
(and (= last-input-char commands/colon) (= :property-search (state/get-editor-action)))
|
||||||
(state/clear-editor-action!)
|
(state/clear-editor-action!)
|
||||||
|
@ -1867,7 +1867,7 @@
|
||||||
(defn block-on-chosen-handler
|
(defn block-on-chosen-handler
|
||||||
[_input id q format]
|
[_input id q format]
|
||||||
(fn [chosen _click?]
|
(fn [chosen _click?]
|
||||||
(state/set-editor-show-block-search! false)
|
(state/clear-editor-action!)
|
||||||
(let [uuid-string (str (:block/uuid chosen))]
|
(let [uuid-string (str (:block/uuid chosen))]
|
||||||
|
|
||||||
;; block reference
|
;; block reference
|
||||||
|
@ -1890,7 +1890,7 @@
|
||||||
(defn block-non-exist-handler
|
(defn block-non-exist-handler
|
||||||
[input]
|
[input]
|
||||||
(fn []
|
(fn []
|
||||||
(state/set-editor-show-block-search! false)
|
(state/clear-editor-action!)
|
||||||
(cursor/move-cursor-forward input 2)))
|
(cursor/move-cursor-forward input 2)))
|
||||||
|
|
||||||
(defn- paste-block-cleanup
|
(defn- paste-block-cleanup
|
||||||
|
@ -2299,7 +2299,7 @@
|
||||||
:check-fn (fn [_ _ _]
|
:check-fn (fn [_ _ _]
|
||||||
(state/set-editor-action-data! {:pos new-pos})
|
(state/set-editor-action-data! {:pos new-pos})
|
||||||
(commands/handle-step [:editor/search-page]))}))]
|
(commands/handle-step [:editor/search-page]))}))]
|
||||||
(state/set-editor-show-page-search! false)
|
(state/clear-editor-action!)
|
||||||
(let [selection (get-selection-and-format)
|
(let [selection (get-selection-and-format)
|
||||||
{:keys [selection-start selection-end selection]} selection]
|
{:keys [selection-start selection-end selection]} selection]
|
||||||
(if selection
|
(if selection
|
||||||
|
@ -2332,7 +2332,7 @@
|
||||||
:check-fn (fn [_ _ _]
|
:check-fn (fn [_ _ _]
|
||||||
(state/set-editor-action-data! {:pos new-pos})
|
(state/set-editor-action-data! {:pos new-pos})
|
||||||
(commands/handle-step [:editor/search-block]))}))]
|
(commands/handle-step [:editor/search-block]))}))]
|
||||||
(state/set-editor-show-block-search! false)
|
(state/clear-editor-action!)
|
||||||
(if-let [embed-ref (thingatpt/embed-macro-at-point input)]
|
(if-let [embed-ref (thingatpt/embed-macro-at-point input)]
|
||||||
(let [{:keys [raw-content start end]} embed-ref]
|
(let [{:keys [raw-content start end]} embed-ref]
|
||||||
(delete-and-update input start end)
|
(delete-and-update input start end)
|
||||||
|
@ -2638,10 +2638,10 @@
|
||||||
(commands/delete-pair! id)
|
(commands/delete-pair! id)
|
||||||
(cond
|
(cond
|
||||||
(and (= deleted "[") (state/get-editor-show-page-search?))
|
(and (= deleted "[") (state/get-editor-show-page-search?))
|
||||||
(state/set-editor-show-page-search! false)
|
(state/clear-editor-action!)
|
||||||
|
|
||||||
(and (= deleted "(") (state/get-editor-show-block-search?))
|
(and (= deleted "(") (state/get-editor-show-block-search?))
|
||||||
(state/set-editor-show-block-search! false)
|
(state/clear-editor-action!)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
nil))
|
nil))
|
||||||
|
@ -2649,7 +2649,7 @@
|
||||||
;; deleting hashtag
|
;; deleting hashtag
|
||||||
(and (= deleted "#") (state/get-editor-show-page-search-hashtag?))
|
(and (= deleted "#") (state/get-editor-show-page-search-hashtag?))
|
||||||
(do
|
(do
|
||||||
(state/set-editor-show-page-search-hashtag! false)
|
(state/clear-editor-action!)
|
||||||
(delete-and-update input (dec current-pos) current-pos))
|
(delete-and-update input (dec current-pos) current-pos))
|
||||||
|
|
||||||
;; just delete
|
;; just delete
|
||||||
|
@ -2729,7 +2729,7 @@
|
||||||
(and (= key "#")
|
(and (= key "#")
|
||||||
(and (> pos 0)
|
(and (> pos 0)
|
||||||
(= "#" (util/nth-safe value (dec pos)))))
|
(= "#" (util/nth-safe value (dec pos)))))
|
||||||
(state/set-editor-show-page-search-hashtag! false)
|
(state/clear-editor-action!)
|
||||||
|
|
||||||
(and (contains? (set/difference (set (keys reversed-autopair-map))
|
(and (contains? (set/difference (set (keys reversed-autopair-map))
|
||||||
#{"`"})
|
#{"`"})
|
||||||
|
@ -2831,7 +2831,7 @@
|
||||||
|
|
||||||
(and (state/get-editor-show-page-search-hashtag?)
|
(and (state/get-editor-show-page-search-hashtag?)
|
||||||
(= c " "))
|
(= c " "))
|
||||||
(state/set-editor-show-page-search-hashtag! false)
|
(state/clear-editor-action!)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(when (and (not editor-action) (not non-enter-processed?))
|
(when (and (not editor-action) (not non-enter-processed?))
|
||||||
|
|
|
@ -683,7 +683,7 @@
|
||||||
;; Editor
|
;; Editor
|
||||||
(defn page-not-exists-handler
|
(defn page-not-exists-handler
|
||||||
[input id q current-pos]
|
[input id q current-pos]
|
||||||
(state/set-editor-show-page-search! false)
|
(state/clear-editor-action!)
|
||||||
(if (state/org-mode-file-link? (state/get-current-repo))
|
(if (state/org-mode-file-link? (state/get-current-repo))
|
||||||
(let [page-ref-text (get-page-ref-text q)
|
(let [page-ref-text (get-page-ref-text q)
|
||||||
value (gobj/get input "value")
|
value (gobj/get input "value")
|
||||||
|
|
|
@ -602,36 +602,18 @@
|
||||||
[]
|
[]
|
||||||
(:editor/action-data @state))
|
(:editor/action-data @state))
|
||||||
|
|
||||||
(defn set-editor-show-page-search!
|
|
||||||
[value]
|
|
||||||
(set-editor-action! (when value :page-search)))
|
|
||||||
|
|
||||||
(defn get-editor-show-page-search?
|
(defn get-editor-show-page-search?
|
||||||
[]
|
[]
|
||||||
(= (get-editor-action) :page-search))
|
(= (get-editor-action) :page-search))
|
||||||
|
|
||||||
(defn set-editor-show-page-search-hashtag!
|
|
||||||
[value]
|
|
||||||
(set-editor-action! (when value :page-search-hashtag)))
|
|
||||||
|
|
||||||
(defn get-editor-show-page-search-hashtag?
|
(defn get-editor-show-page-search-hashtag?
|
||||||
[]
|
[]
|
||||||
(= (get-editor-action) :page-search-hashtag))
|
(= (get-editor-action) :page-search-hashtag))
|
||||||
(defn set-editor-show-block-search!
|
|
||||||
[value]
|
|
||||||
(set-editor-action! (when value :block-search)))
|
|
||||||
(defn get-editor-show-block-search?
|
(defn get-editor-show-block-search?
|
||||||
[]
|
[]
|
||||||
(= (get-editor-action) :block-search))
|
(= (get-editor-action) :block-search))
|
||||||
(defn set-editor-show-template-search!
|
|
||||||
[value]
|
|
||||||
(set-editor-action! (when value :template-search)))
|
|
||||||
(defn set-editor-show-property-search!
|
|
||||||
[value]
|
|
||||||
(set-editor-action! (when value :property-search)))
|
|
||||||
(defn set-editor-show-date-picker!
|
|
||||||
[value]
|
|
||||||
(set-editor-action! (when value :datepicker)))
|
|
||||||
(defn set-editor-show-input!
|
(defn set-editor-show-input!
|
||||||
[value]
|
[value]
|
||||||
(if value
|
(if value
|
||||||
|
@ -652,10 +634,6 @@
|
||||||
[]
|
[]
|
||||||
(when-not (get-editor-action) (set-editor-action! :block-commands)))
|
(when-not (get-editor-action) (set-editor-action! :block-commands)))
|
||||||
|
|
||||||
(defn set-editor-show-zotero!
|
|
||||||
[value]
|
|
||||||
(set-state! :editor/show-zotero value))
|
|
||||||
|
|
||||||
(defn clear-editor-action!
|
(defn clear-editor-action!
|
||||||
[]
|
[]
|
||||||
(swap! state (fn [state]
|
(swap! state (fn [state]
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
|
|
||||||
(defn get-string-all-indexes
|
(defn get-string-all-indexes
|
||||||
"Get all indexes of `value` in the string `s`."
|
"Get all indexes of `value` in the string `s`."
|
||||||
[s value before?]
|
[s value {:keys [before?] :or {before? true}}]
|
||||||
(if (= value "")
|
(if (= value "")
|
||||||
(if before? [0] [(dec (count s))])
|
(if before? [0] [(dec (count s))])
|
||||||
(loop [acc []
|
(loop [acc []
|
||||||
|
@ -98,9 +98,9 @@
|
||||||
(defn wrapped-by?
|
(defn wrapped-by?
|
||||||
"`pos` must be wrapped by `before` and `and` in string `value`, e.g. ((a|b))"
|
"`pos` must be wrapped by `before` and `and` in string `value`, e.g. ((a|b))"
|
||||||
[value pos before end]
|
[value pos before end]
|
||||||
(let [before-matches (->> (get-string-all-indexes value before true)
|
(let [before-matches (->> (get-string-all-indexes value before {:before? true})
|
||||||
(map (fn [i] [i :before])))
|
(map (fn [i] [i :before])))
|
||||||
end-matches (->> (get-string-all-indexes value end false)
|
end-matches (->> (get-string-all-indexes value end {:before? false})
|
||||||
(map (fn [i] [i :end])))
|
(map (fn [i] [i :end])))
|
||||||
indexes (sort-by first (concat before-matches end-matches [[pos :between]]))
|
indexes (sort-by first (concat before-matches end-matches [[pos :between]]))
|
||||||
ks (map second indexes)
|
ks (map second indexes)
|
||||||
|
|
|
@ -23,11 +23,11 @@
|
||||||
(deftest get-string-all-indexes
|
(deftest get-string-all-indexes
|
||||||
[]
|
[]
|
||||||
(are [x y] (= x y)
|
(are [x y] (= x y)
|
||||||
(text-util/get-string-all-indexes "[[hello]] [[world]]" "[[" true)
|
(text-util/get-string-all-indexes "[[hello]] [[world]]" "[[" {})
|
||||||
[0 10]
|
[0 10]
|
||||||
|
|
||||||
(text-util/get-string-all-indexes "abc abc ab" "ab" true)
|
(text-util/get-string-all-indexes "abc abc ab" "ab" {})
|
||||||
[0 4 8]
|
[0 4 8]
|
||||||
|
|
||||||
(text-util/get-string-all-indexes "a.c a.c ab" "a." true)
|
(text-util/get-string-all-indexes "a.c a.c ab" "a." {})
|
||||||
[0 4]))
|
[0 4]))
|
||||||
|
|
Loading…
Reference in New Issue