Improve backtick autopairing (#6496)

* If you type a backtick and then some letters and then another backtick, the last backtick should close the first one and not spawn another autopair
pull/6498/head
Viktor Moros 2022-08-26 21:32:46 -07:00 committed by GitHub
parent b47826d69d
commit f5824322b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -2720,9 +2720,15 @@
(do (util/stop e)
(autopair input-id "(" format nil))
;; If you type `xyz`, the last backtick should close the first and not add another autopair
;; If you type several backticks in a row, each one should autopair to accommodate multiline code (```)
(contains? (set (keys autopair-map)) key)
(do (util/stop e)
(autopair input-id key format nil))
(let [curr (get-current-input-char input)
prev (util/nth-safe value (dec pos))]
(util/stop e)
(if (and (= key "`") (= "`" curr) (not= "`" prev))
(cursor/move-cursor-forward input)
(autopair input-id key format nil)))
(and hashtag? (or (zero? pos) (re-matches #"\s" (get value (dec pos)))))
(do

View File

@ -66,7 +66,7 @@
result)))
(defn surround-by?
"`pos` must be surrounded by `before` and `and` in string `value`, e.g. ((|))"
"`pos` must be surrounded by `before` and `end` in string `value`, e.g. ((|))"
[value pos before end]
(let [start-pos (if (= :start before) 0 (- pos (count before)))
end-pos (if (= :end end) (count value) (+ pos (count end)))]
@ -97,7 +97,7 @@
acc))))
(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 `end` in string `value`, e.g. ((a|b))"
[value pos before end]
;; Increment 'before' matches by (length of before string - 0.5) to make them be just before the cursor position they precede.
;; Increment 'after' matches by 0.5 to make them be just after the cursor position they follow.