mirror of
https://github.com/logseq/logseq.git
synced 2026-05-24 12:44:22 +00:00
@@ -326,8 +326,9 @@
|
||||
{:keys [last-pattern postfix-fn backward-pos end-pattern backward-truncate-number command]
|
||||
:as _option}]
|
||||
(when-let [input (gdom/getElement id)]
|
||||
(let [last-pattern (when-not backward-truncate-number
|
||||
(or last-pattern (state/get-editor-command-trigger)))
|
||||
(let [last-pattern (when-not (= last-pattern :skip-check)
|
||||
(when-not backward-truncate-number
|
||||
(or last-pattern (state/get-editor-command-trigger))))
|
||||
edit-content (gobj/get input "value")
|
||||
current-pos (cursor/pos input)
|
||||
current-pos (or
|
||||
|
||||
@@ -2915,6 +2915,13 @@
|
||||
:else
|
||||
nil))))
|
||||
|
||||
(defn- input-page-ref?
|
||||
[k current-pos blank-selected? last-key-code]
|
||||
(and blank-selected?
|
||||
(contains? keycode/left-square-brackets-keys k)
|
||||
(= (:key last-key-code) k)
|
||||
(> current-pos 0)))
|
||||
|
||||
(defn- default-case-for-keyup-handler
|
||||
[input current-pos k code is-processed? c]
|
||||
(let [last-key-code (state/get-last-key-code)
|
||||
@@ -2922,59 +2929,63 @@
|
||||
non-enter-processed? (and is-processed? ;; #3251
|
||||
(not= code keycode/enter-code)) ;; #3459
|
||||
editor-action (state/get-editor-action)]
|
||||
(when (and (not editor-action) (not non-enter-processed?))
|
||||
(cond
|
||||
;; When you type text inside square brackets
|
||||
(and (not (contains? #{"ArrowDown" "ArrowLeft" "ArrowRight" "ArrowUp" "Escape"} k))
|
||||
(wrapped-by? input page-ref/left-brackets page-ref/right-brackets))
|
||||
(let [orig-pos (cursor/get-caret-pos input)
|
||||
value (gobj/get input "value")
|
||||
square-pos (string/last-index-of (subs value 0 (:pos orig-pos)) page-ref/left-brackets)
|
||||
pos (+ square-pos 2)
|
||||
_ (state/set-editor-last-pos! pos)
|
||||
pos (assoc orig-pos :pos pos)
|
||||
command-step (if (= \# (util/nth-safe value (dec square-pos)))
|
||||
:editor/search-page-hashtag
|
||||
:editor/search-page)]
|
||||
(commands/handle-step [command-step])
|
||||
(state/set-editor-action-data! {:pos pos}))
|
||||
(if (and (= editor-action :page-search-hashtag)
|
||||
(input-page-ref? k current-pos blank-selected? last-key-code))
|
||||
(do
|
||||
(commands/handle-step [:editor/input page-ref/right-brackets {:last-pattern :skip-check
|
||||
:backward-pos 2}])
|
||||
(commands/handle-step [:editor/search-page])
|
||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))
|
||||
(when (and (not editor-action) (not non-enter-processed?))
|
||||
(cond
|
||||
;; When you type text inside square brackets
|
||||
(and (not (contains? #{"ArrowDown" "ArrowLeft" "ArrowRight" "ArrowUp" "Escape"} k))
|
||||
(wrapped-by? input page-ref/left-brackets page-ref/right-brackets))
|
||||
(let [orig-pos (cursor/get-caret-pos input)
|
||||
value (gobj/get input "value")
|
||||
square-pos (string/last-index-of (subs value 0 (:pos orig-pos)) page-ref/left-brackets)
|
||||
pos (+ square-pos 2)
|
||||
_ (state/set-editor-last-pos! pos)
|
||||
pos (assoc orig-pos :pos pos)
|
||||
command-step (if (= \# (util/nth-safe value (dec square-pos)))
|
||||
:editor/search-page-hashtag
|
||||
:editor/search-page)]
|
||||
(commands/handle-step [command-step])
|
||||
(state/set-editor-action-data! {:pos pos}))
|
||||
|
||||
;; Handle non-ascii square brackets
|
||||
(and blank-selected?
|
||||
(contains? keycode/left-square-brackets-keys k)
|
||||
(= (:key last-key-code) k)
|
||||
(> current-pos 0)
|
||||
(not (wrapped-by? input page-ref/left-brackets page-ref/right-brackets)))
|
||||
(do
|
||||
(commands/handle-step [:editor/input page-ref/left-and-right-brackets {:backward-truncate-number 2
|
||||
;; Handle non-ascii square brackets
|
||||
(and (input-page-ref? k current-pos blank-selected? last-key-code)
|
||||
(not (wrapped-by? input page-ref/left-brackets page-ref/right-brackets)))
|
||||
(do
|
||||
(commands/handle-step [:editor/input page-ref/left-and-right-brackets {:backward-truncate-number 2
|
||||
:backward-pos 2}])
|
||||
(commands/handle-step [:editor/search-page])
|
||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))
|
||||
|
||||
;; Handle non-ascii parentheses
|
||||
(and blank-selected?
|
||||
(contains? keycode/left-paren-keys k)
|
||||
(= (:key last-key-code) k)
|
||||
(> current-pos 0)
|
||||
(not (wrapped-by? input block-ref/left-parens block-ref/right-parens)))
|
||||
(do
|
||||
(commands/handle-step [:editor/input block-ref/left-and-right-parens {:backward-truncate-number 2
|
||||
:backward-pos 2}])
|
||||
(commands/handle-step [:editor/search-page])
|
||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))
|
||||
(commands/handle-step [:editor/search-block :reference])
|
||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))
|
||||
|
||||
;; Handle non-ascii parentheses
|
||||
(and blank-selected?
|
||||
(contains? keycode/left-paren-keys k)
|
||||
(= (:key last-key-code) k)
|
||||
(> current-pos 0)
|
||||
(not (wrapped-by? input block-ref/left-parens block-ref/right-parens)))
|
||||
(do
|
||||
(commands/handle-step [:editor/input block-ref/left-and-right-parens {:backward-truncate-number 2
|
||||
:backward-pos 2}])
|
||||
(commands/handle-step [:editor/search-block :reference])
|
||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))
|
||||
;; Handle non-ascii angle brackets
|
||||
(and (= "〈" c)
|
||||
(= "《" (util/nth-safe (gobj/get input "value") (dec (dec current-pos))))
|
||||
(> current-pos 0))
|
||||
(do
|
||||
(commands/handle-step [:editor/input commands/angle-bracket {:last-pattern "《〈"
|
||||
:backward-pos 0}])
|
||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
|
||||
(state/set-editor-show-block-commands!))
|
||||
|
||||
;; Handle non-ascii angle brackets
|
||||
(and (= "〈" c)
|
||||
(= "《" (util/nth-safe (gobj/get input "value") (dec (dec current-pos))))
|
||||
(> current-pos 0))
|
||||
(do
|
||||
(commands/handle-step [:editor/input commands/angle-bracket {:last-pattern "《〈"
|
||||
:backward-pos 0}])
|
||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
|
||||
(state/set-editor-show-block-commands!))
|
||||
|
||||
:else
|
||||
nil))))
|
||||
:else
|
||||
nil)))))
|
||||
|
||||
(defn keyup-handler
|
||||
[_state input input-id]
|
||||
|
||||
Reference in New Issue
Block a user