 
 (defn save! [^Scene scene]
   (when-let [path (:selection @pref-state)]
-    (when-let [engine (some-> scene (.lookup "#webview") .getEngine)]
-      (e/save-file! path engine))
+    (when-let [pane (get-in @runtime-state [:editor-panes path])]
+      (when-let [engine (some-> pane (.lookup "#webview") .getEngine)]
+        (e/save-file! path engine)))
     ; if saving a build.boot file, refresh the build buttons
     (let [file (io/file path)
           parent-path (-> file .getParentFile .getCanonicalPath)]

; undo

(defn undo! [^Scene scene]
  (let [editor (.lookup scene "#editor")
        webview (.lookup scene "#webview")
        engine (.getEngine webview)]
    (.executeScript engine "undo()")
    (e/update-editor-buttons! editor engine)))

(defn -onUndo [this ^ActionEvent event]
  (-> event .getSource .getScene undo!))

; find

(defn focus-on-find! [^Scene scene]
  (when-let [path (:selection @pref-state)]
    (when-let [pane (get-in @runtime-state [:editor-panes path])]
      (when-let [find (.lookup pane "#find")]
        (doto find .requestFocus .selectAll)))))

(defn find! [^Scene scene ^KeyEvent event]
  (when (= KeyCode/ENTER (.getCode event))
    (when-let [path (:selection @pref-state)]
      (when-let [pane (get-in @runtime-state [:editor-panes path])]
        (let [webview (.lookup pane "#webview")
              engine (.getEngine webview)
              find (.lookup pane "#find")
              find-text (.getText find)]
          (-> engine
              (.executeScript "window")
              (.call "find" (into-array Object [find-text true (.isShiftDown event)]))))))))

(defn -onFind [this ^KeyEvent event]
  (-> event .getSource .getScene (find! event)))
