Browse Source

#7349 Autopair parenthesis (#7379)

* Activate auto complete only if there's whitespace (\s) preceding the opening paranthesis, except when opening parenthesis is preceded by closing square bracket (]). In cases such as URLs

* #7349 Activate auto complete alson when there's a left parenthesis preceding the opening paranthesis.
Jon 2 years ago
parent
commit
12f1517fdf
1 changed files with 14 additions and 1 deletions
  1. 14 1
      src/main/frontend/handler/editor.cljs

+ 14 - 1
src/main/frontend/handler/editor.cljs

@@ -1573,6 +1573,15 @@
           pos (cursor/pos input)]
       (text-util/surround-by? value pos before end))))
 
+(defn- autopair-left-paren?
+  [input key]
+  (and (= key "(")
+       (or
+         (surround-by? input :start "")
+         (surround-by? input " " "")
+         (surround-by? input "]" "")
+         (surround-by? input "(" ""))))
+
 (defn wrapped-by?
   [input before end]
   (when input
@@ -2730,7 +2739,11 @@
 
         ;; 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)
+        (-> (keys autopair-map)
+            set
+            (disj "(")
+            (contains? key)
+            (or (autopair-left-paren? input key)))
         (let [curr (get-current-input-char input)
                   prev (util/nth-safe value (dec pos))]
             (util/stop e)