mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-24 18:22:58 +02:00
UI: Add option to autosave scripts on focus change (#2565)
This commit is contained in:
@@ -13,6 +13,9 @@ import reactDomTypes from "../../../node_modules/@types/react-dom/index.d.ts?raw
|
||||
|
||||
import { useScriptEditorContext } from "./ScriptEditorContext";
|
||||
import { scriptEditor } from "../ScriptEditor";
|
||||
import { Settings } from "../../Settings/Settings";
|
||||
import { openScripts } from "../EditorData";
|
||||
import { isUnsavedFile, saveScript } from "./utils";
|
||||
|
||||
interface EditorProps {
|
||||
/** Function to be ran after mounting editor */
|
||||
@@ -63,6 +66,17 @@ export function Editor({ onMount, onChange, onUnmount }: EditorProps) {
|
||||
subscription.current = editorRef.current.onDidChangeModelContent(() => {
|
||||
onChange(editorRef.current?.getValue());
|
||||
});
|
||||
editorRef.current.onDidBlurEditorWidget(() => {
|
||||
if (!Settings.MonacoAutoSaveOnFocusChange) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < openScripts.length; ++i) {
|
||||
if (!isUnsavedFile(openScripts, i)) {
|
||||
continue;
|
||||
}
|
||||
saveScript(openScripts[i]);
|
||||
}
|
||||
});
|
||||
|
||||
// Unmounting
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user