diff --git a/src/plugins/textReplace/index.tsx b/src/plugins/textReplace/index.tsx index 8e70d85c..81cea86e 100644 --- a/src/plugins/textReplace/index.tsx +++ b/src/plugins/textReplace/index.tsx @@ -34,7 +34,7 @@ import { React, TextInput, useState } from "@webpack/common"; const cl = classNameFactory("vc-textReplace-"); -type Rule = Record<"find" | "replace" | "onlyIfIncludes", string>; +type Rule = Record<"find" | "replace" | "onlyIfIncludes" | "id", string>; interface TextReplaceProps { title: string; @@ -46,7 +46,8 @@ interface TextReplaceProps { const makeEmptyRule: () => Rule = () => ({ find: "", replace: "", - onlyIfIncludes: "" + onlyIfIncludes: "", + id: crypto.randomUUID() }); const makeEmptyRuleArray = () => [makeEmptyRule()]; @@ -123,7 +124,7 @@ function Input({ initialValue, onChange, placeholder }: { value={value} onChange={setValue} spellCheck={false} - onBlur={() => value !== initialValue && onChange(value)} + onBlur={() => value !== initialValue && setTimeout(() => onChange(value), 0)} /> ); } @@ -168,7 +169,7 @@ function TextReplace({ title, description, rulesArray, isRegex = false }: TextRe {rulesArray.map((rule, index) => ( <>
@@ -272,6 +273,11 @@ export default definePlugin({ settings, + start() { + settings.store.regexRules.forEach(rule => rule.id ??= crypto.randomUUID()); + settings.store.stringRules.forEach(rule => rule.id ??= crypto.randomUUID()); + }, + onBeforeMessageSend(channelId, msg) { // Channel used for sharing rules, applying rules here would be messy if (channelId === TEXT_REPLACE_RULES_CHANNEL_ID) return;