 
 (defn load-prev-image [state]
   (load-image state
-              (let [prev-file (->> (:file-list state)
+              (let [prev-file (->> (filter-query (:file-query state) (:file-list state))
                                    (take-while (complement #{(:image-file state)}) )
                                    (last))]
                 (or prev-file (last (:file-list state))))))
 
 (defn key-pressed [state e]
   (println e)
-  (if (:typing state)
+  (if-let [field (:typing state)]
     (case (:key-code e)
       10 (assoc state :typing false)
-      8  (update-in state [:query] #(apply str (drop-last %)))
-      47 (assoc state :query "") ;; /
+      8  (update-in state [field] #(apply str (drop-last %)))
+      47 (assoc state field "") ;; /
       27 (do (set! (.key (a/current-applet)) (char 0))
-             (reset! (:debug state) nil)
-             (assoc state :typing false :query ""))
+             (when (= :query field) (reset! (:debug state) nil))
+             (assoc state :typing false field ""))
       (if (<= 32 (:key-code e) 128)
-        (update-in state [:query] #(str % (:raw-key e)))
+        (update-in state [field] #(str % (:raw-key e)))
         state))
 
     ;; not typing

      :h (update-in state [:left] #(- % 15))
      :+ (update-in state [:zoom] #(* % 2))
      :- (update-in state [:zoom] #(/ % 2))
      :/ (assoc state :typing true :query "")
      :down (load-next-image state)
      :up (load-prev-image state)
      :left (update-in state [:debug-offset] dec)


(defn load-next-image [state]
  (load-image state
              (let [next-file (->> (filter-query (:file-query state) (:file-list state))
                                   (partition-by #{(:image-file state)})
                                   (remove #{(list (:image-file state))})
                                   (last)
