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

; redo

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

(defn -onRedo [this ^ActionEvent event]
  (-> event .getSource .getScene redo!))

; instaREPL

(defn toggle-instarepl! [^Scene scene & [from-button?]]
  (when-let [path (:selection @pref-state)]
    (when-let [pane (get-in @runtime-state [:editor-panes path])]
      (let [webview (.lookup pane "#webview")
            instarepl (.lookup pane "#instarepl")]
        (when-not from-button?
          (.setSelected instarepl (not (.isSelected instarepl))))
        (e/toggle-instarepl! (.getEngine webview) (.isSelected instarepl))))))

(defn -onInstaRepl [this ^ActionEvent event]
  (-> event .getSource .getScene (toggle-instarepl! true)))
