feat: swap out caret_pos imp

This commit is contained in:
Weihua Lu
2021-06-09 18:46:50 +08:00
committed by Tienson Qin
parent 3cbf3b74be
commit 669dac7a09
4 changed files with 53 additions and 52 deletions

View File

@@ -1532,12 +1532,12 @@
"[["
(do
(commands/handle-step [:editor/search-page])
(reset! commands/*slash-caret-pos (util/get-caret-pos input)))
(reset! commands/*slash-caret-pos (cursor/get-caret-pos input)))
"(("
(do
(commands/handle-step [:editor/search-block :reference])
(reset! commands/*slash-caret-pos (util/get-caret-pos input)))
(reset! commands/*slash-caret-pos (cursor/get-caret-pos input)))
nil)))))
@@ -1848,7 +1848,6 @@
(defn edit-box-on-change!
[e block id]
(let [value (util/evalue e)
current-pos (util/get-input-pos (gdom/getElement id))
repo (or (:block/repo block)
(state/get-current-repo))]
(state/set-edit-content! id value false)
@@ -1862,22 +1861,24 @@
(state/set-editor-op! :auto-save)
(save-current-block! {})
(state/set-editor-op! nil)))
500))
(let [input (gdom/getElement id)
native-e (gobj/get e "nativeEvent")
last-input-char (util/nth-safe value (dec current-pos))]
(case last-input-char
"/"
;; TODO: is it cross-browser compatible?
(when (not= (gobj/get native-e "inputType") "insertFromPaste")
(when-let [matched-commands (seq (get-matched-commands input))]
(reset! commands/*slash-caret-pos (util/get-caret-pos input))
(reset! commands/*show-commands true)))
"<"
(when-let [matched-commands (seq (get-matched-block-commands input))]
(reset! commands/*angle-bracket-caret-pos (util/get-caret-pos input))
(reset! commands/*show-block-commands true))
nil))))
500))))
(defn handle-last-input []
(let [input (state/get-input)
pos (cursor/pos input)
last-input-char (util/nth-safe (.-value input) (dec pos))]
(case last-input-char
"/"
;; TODO: is it cross-browser compatible?
;; (not= (gobj/get native-e "inputType") "insertFromPaste")
(when (seq (get-matched-commands input))
(reset! commands/*slash-caret-pos (cursor/get-caret-pos input))
(reset! commands/*show-commands true))
"<"
(when (seq (get-matched-block-commands input))
(reset! commands/*angle-bracket-caret-pos (cursor/get-caret-pos input))
(reset! commands/*show-block-commands true))
nil)))
(defn block-on-chosen-handler
[input id q format]
@@ -2515,11 +2516,11 @@
(surround-by? input "[[" "]]")
(do
(commands/handle-step [:editor/search-page])
(reset! commands/*slash-caret-pos (util/get-caret-pos input)))
(reset! commands/*slash-caret-pos (cursor/get-caret-pos input)))
(surround-by? input "((" "))")
(do
(commands/handle-step [:editor/search-block :reference])
(reset! commands/*slash-caret-pos (util/get-caret-pos input)))
(reset! commands/*slash-caret-pos (cursor/get-caret-pos input)))
:else
nil))
@@ -2530,7 +2531,7 @@
(do
(commands/handle-step [:editor/search-page-hashtag])
(state/set-last-pos! (cursor/pos input))
(reset! commands/*slash-caret-pos (util/get-caret-pos input)))
(reset! commands/*slash-caret-pos (cursor/get-caret-pos input)))
(let [sym "$"]
(and (= key sym)
@@ -2571,7 +2572,7 @@
(commands/handle-step [:editor/input "[[]]" {:last-pattern "【【"
:backward-pos 2}])
(commands/handle-step [:editor/search-page])
(reset! commands/*slash-caret-pos (util/get-caret-pos input)))
(reset! commands/*slash-caret-pos (cursor/get-caret-pos input)))
(when (and (or (= k "(") (= k ""))
(> current-pos 0)
@@ -2579,7 +2580,7 @@
(commands/handle-step [:editor/input "(())" {:last-pattern ""
:backward-pos 2}])
(commands/handle-step [:editor/search-block :reference])
(reset! commands/*slash-caret-pos (util/get-caret-pos input)))
(reset! commands/*slash-caret-pos (cursor/get-caret-pos input)))
(when (= c " ")
(when (or (= (util/nth-safe value (dec (dec current-pos))) "#")