|
|
@@ -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}))
|
|
|
-
|
|
|
- ;; 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
|
|
|
+ (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 (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)}))
|
|
|
-
|
|
|
- ;; 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!))
|
|
|
-
|
|
|
- :else
|
|
|
- nil))))
|
|
|
+ (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!))
|
|
|
+
|
|
|
+ :else
|
|
|
+ nil)))))
|
|
|
|
|
|
(defn keyup-handler
|
|
|
[_state input input-id]
|