diff --git a/src/components/CheckedTextInput.tsx b/src/components/CheckedTextInput.tsx
index cf4aa119..de2d7ae0 100644
--- a/src/components/CheckedTextInput.tsx
+++ b/src/components/CheckedTextInput.tsx
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-import { React, TextInput } from "@webpack/common";
+import { React, TextInput, useEffect } from "@webpack/common";
// TODO: Refactor settings to use this as well
interface TextInputProps {
@@ -55,6 +55,10 @@ export function CheckedTextInput({ value: initialValue, onChange, validate }: Te
}
}
+ useEffect(() => {
+ handleChange(initialValue);
+ }, [initialValue]);
+
return (
<>
("");
+ const [fullPatchError, setFullPatchError] = React.useState("");
+
+ function update() {
+ if (fullPatch === "") {
+ setFullPatchError("");
+
+ setFind("");
+ setMatch("");
+ setReplacement("");
+ return;
+ }
+
+ try {
+ const parsed = (0, eval)(`(${fullPatch})`) as Patch;
+
+ if (!parsed.find) throw new Error("No 'find' field");
+ if (!parsed.replacement) throw new Error("No 'replacement' field");
+
+ if (parsed.replacement instanceof Array) {
+ if (parsed.replacement.length === 0) throw new Error("Invalid replacement");
+
+ parsed.replacement = {
+ match: parsed.replacement[0].match,
+ replace: parsed.replacement[0].replace
+ };
+ }
+
+ if (!parsed.replacement.match) throw new Error("No 'replacement.match' field");
+ if (!parsed.replacement.replace) throw new Error("No 'replacement.replace' field");
+
+ setFind(parsed.find);
+ setMatch(parsed.replacement.match instanceof RegExp ? parsed.replacement.match.source : parsed.replacement.match);
+ setReplacement(parsed.replacement.replace);
+ setFullPatchError("");
+ } catch (e) {
+ setFullPatchError((e as Error).message);
+ }
+ }
+
+ return <>
+ Paste your full JSON patch here to fill out the fields
+
+ {fullPatchError !== "" && {fullPatchError}}
+ >;
+}
+
function PatchHelper() {
const [find, setFind] = React.useState("");
const [match, setMatch] = React.useState("");
@@ -260,6 +314,13 @@ function PatchHelper() {
return (
+ full patch
+
+
find