 
 (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)]

; find

(defn focus-on-find! [^Scene scene]
  (when-let [find (.lookup scene "#find")]
    (doto find .requestFocus .selectAll)))

(defn find! [^Scene scene ^KeyEvent event]
  (when (= KeyCode/ENTER (.getCode event))
    (when-let [path (:selection @pref-state)]
      (let [webview (.lookup scene "#webview")
            engine (.getEngine webview)
            find (.lookup scene "#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)))

; undo

(defn undo! [^Scene scene]
  (when-let [path (:selection @pref-state)]
    (when-let [pane (get-in @runtime-state [:editor-panes path])]
      (let [webview (.lookup pane "#webview")
            engine (.getEngine webview)]
        (.executeScript engine "undo()")
        (e/update-editor-buttons! pane engine)))))

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