 (behavior ::repeat-pair
           :triggers #{:repeat-pair!}
           :reaction (fn [this ch]
-                      (cond
-                       (= ch (get-char this 1)) (move-cursor this 1)
-                       (re-seq word-char (get-char this 1)) (editor/insert-at-cursor this ch)
-                       (re-seq word-char (get-char this -1)) (editor/insert-at-cursor this ch)
-                       :else (do
-                               (editor/insert-at-cursor this (str ch ch))
-                               (move-cursor this -1)))))
+                      (let [current-selection (editor/selection this)]
+                        (if-not (= something-selected "")
+                          (editor/replace-selection this (str ch current-selection ch))
+                          (cond
+                           (= ch (get-char this 1)) (move-cursor this 1)
+                           (re-seq word-char (get-char this 1)) (editor/insert-at-cursor this ch)
+                           (re-seq word-char (get-char this -1)) (editor/insert-at-cursor this ch)
+                           :else (do
+                                   (editor/insert-at-cursor this (str ch ch))
+                                   (move-cursor this -1)))))))
 
 (behavior ::try-remove-pair
           :triggers #{:backspace!}

(behavior ::open-pair
          :triggers #{:open-pair!}
          :reaction (fn [this ch]
                      (if (re-seq word-char (get-char this 1))
                        (editor/insert-at-cursor this ch)
                        (do
                          (editor/insert-at-cursor this (str ch (pairs ch)))
                          (move-cursor this -1)))))

(behavior ::close-pair
          :triggers #{:close-pair!}

  (:require [lt.object :as object]
            [lt.objs.command :as cmd]
            [lt.objs.editor :as editor]
            [lt.objs.editor.pool :as pool]
            [lt.objs.context :as ctx]
            [lt.objs.keyboard :refer [passthrough]])
  (:require-macros [lt.macros :refer [behavior]]))
