Skip to content

Commit

Permalink
fix: auto-complete for and
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushAgrawal-A2 authored and andelf committed Apr 23, 2024
1 parent 157fa1e commit 2150c6a
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,15 +1580,16 @@
"^" "^"
"=" "="
"/" "/"
"+" "+"})
"+" "+"
"$" "$"})
;; ":" ":" ; TODO: only properties editing and org mode tag

(def reversed-autopair-map
(zipmap (vals autopair-map)
(keys autopair-map)))

(def autopair-when-selected
#{"*" "^" "_" "=" "+" "/"})
#{"*" "^" "_" "=" "+" "/" "$"})

(def delete-map
(assoc autopair-map
Expand Down Expand Up @@ -2901,6 +2902,26 @@
(= (get-current-input-char input) key))
(do (util/stop e)
(cursor/move-cursor-forward input))

(let [sym "$"]
(and (= key sym)
(>= (count value) 1)
(> pos 0)
(= (nth value (dec pos)) sym)
(if (> (count value) pos)
(not= (nth value pos) sym)
true)))
(commands/simple-insert! input-id "$$" {:backward-pos 2})

(let [sym "^"]
(and (= key sym)
(>= (count value) 1)
(> pos 0)
(= (nth value (dec pos)) sym)
(if (> (count value) pos)
(not= (nth value pos) sym)
true)))
(commands/simple-insert! input-id "^^" {:backward-pos 2})

(and (autopair-when-selected key) (string/blank? (util/get-selected-text)))
nil
Expand Down Expand Up @@ -2932,26 +2953,6 @@
(cursor/move-cursor-forward input)
(autopair input-id key format nil)))

(let [sym "$"]
(and (= key sym)
(>= (count value) 1)
(> pos 0)
(= (nth value (dec pos)) sym)
(if (> (count value) pos)
(not= (nth value pos) sym)
true)))
(commands/simple-insert! input-id "$$" {:backward-pos 2})

(let [sym "^"]
(and (= key sym)
(>= (count value) 1)
(> pos 0)
(= (nth value (dec pos)) sym)
(if (> (count value) pos)
(not= (nth value pos) sym)
true)))
(commands/simple-insert! input-id "^^" {:backward-pos 2})

:else
nil))))

Expand Down

0 comments on commit 2150c6a

Please sign in to comment.