           (editor/move-cursor ed p))))))
 
 
+(defn cycle-if* [ed]
+  (let [pos (editor/->cursor ed)
+        form (u/get-top-level-form ed pos)
+        zloc (some-> form
+                     :form-str
+                     z/of-string
+                     (z/find-last-by-pos (u/->zipper-pos-start pos form)))]
+
+    (when-let [res (some-> zloc cycle-if z/root-string)]
+      (editor/replace ed (:start form) (:end form) res)
+      (editor/move-cursor ed pos)
+      (u/format-keep-pos ed))))
+
 
 
 (behavior ::cycle-if!
           :triggers #{:refactor.cycle-if!}
           :reaction (fn [ed]
-                      (replace-cmd ed cycle-if :fmt true)))
+                      (cycle-if* ed)))
 
 (behavior ::cycle-col!
           :triggers #{:refactor.cycle-col!}

       (= (.substr form-str 0 2) "#{") (wrap-in "(" ")" 2)
       :else nil))))


(defn find-node [start candidate-str]
  (loop [cur start]
    (cond
     (= (-> cur z/node str) candidate-str) cur
     (not (z/end? cur)) (recur (z/next cur))
    :else nil)))



(defn move-up [form-str candidate-str]
  (let [root (p/str->seq-zip form-str)
        loc? (when (seq root) (find-node root candidate-str))]
    (when (and loc? (z/node (z/remove loc?)))
      (z/root (z/insert-left (z/remove loc?) (z/node loc?))))))

;;(move-up "(+ 1 (\"__jalla__\" \"dill\"))" "__jalla__")

;;(move-up "(\"__jalla__\")" "__jalla__")


;; DOH no negative lookbehind in JS
;;"(?<!if|\bif-not\b)\s\(" "\n("
(defn inject-nl[form-str]
  (let [idx-a (.indexOf form-str "if (")
        idx-b (.indexOf form-str "if-not (")]
    (cond
     (= -1 idx-a idx-b) (s/replace form-str #"\s\(" "\n(")
     (> idx-a idx-b) (str (.substr form-str 0 (+ idx-a 4))
                          (inject-nl (.substr form-str (+ idx-a 4))))
     :else (str (.substr form-str 0 (+ idx-b 8))
                (inject-nl (.substr form-str (+ idx-b 8)))))))


;; Silly simplistic...
(defn format-form [form-str]
  (-> form-str
      inject-nl))


(defn replace-cmd [ed replace-fn & {:keys [fmt]}]

              :exec (fn []
                      (when-let [ed (pool/last-active)]
                        (object/raise ed :refactor.cycle-col!)))})
