TextReplace: fix rule section closing when changing find
This commit is contained in:
parent
8588ab70d2
commit
f766ea6b49
1 changed files with 10 additions and 4 deletions
|
|
@ -34,7 +34,7 @@ import { React, TextInput, useState } from "@webpack/common";
|
||||||
|
|
||||||
const cl = classNameFactory("vc-textReplace-");
|
const cl = classNameFactory("vc-textReplace-");
|
||||||
|
|
||||||
type Rule = Record<"find" | "replace" | "onlyIfIncludes", string>;
|
type Rule = Record<"find" | "replace" | "onlyIfIncludes" | "id", string>;
|
||||||
|
|
||||||
interface TextReplaceProps {
|
interface TextReplaceProps {
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -46,7 +46,8 @@ interface TextReplaceProps {
|
||||||
const makeEmptyRule: () => Rule = () => ({
|
const makeEmptyRule: () => Rule = () => ({
|
||||||
find: "",
|
find: "",
|
||||||
replace: "",
|
replace: "",
|
||||||
onlyIfIncludes: ""
|
onlyIfIncludes: "",
|
||||||
|
id: crypto.randomUUID()
|
||||||
});
|
});
|
||||||
const makeEmptyRuleArray = () => [makeEmptyRule()];
|
const makeEmptyRuleArray = () => [makeEmptyRule()];
|
||||||
|
|
||||||
|
|
@ -123,7 +124,7 @@ function Input({ initialValue, onChange, placeholder }: {
|
||||||
value={value}
|
value={value}
|
||||||
onChange={setValue}
|
onChange={setValue}
|
||||||
spellCheck={false}
|
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
|
||||||
<Flex flexDirection="column" style={{ gap: "0.5em" }}>
|
<Flex flexDirection="column" style={{ gap: "0.5em" }}>
|
||||||
{rulesArray.map((rule, index) =>
|
{rulesArray.map((rule, index) =>
|
||||||
<ExpandableSection
|
<ExpandableSection
|
||||||
key={`${rule.find}-${index}`}
|
key={rule.id}
|
||||||
renderContent={() => (
|
renderContent={() => (
|
||||||
<>
|
<>
|
||||||
<div className={cl("input-grid")}>
|
<div className={cl("input-grid")}>
|
||||||
|
|
@ -272,6 +273,11 @@ export default definePlugin({
|
||||||
|
|
||||||
settings,
|
settings,
|
||||||
|
|
||||||
|
start() {
|
||||||
|
settings.store.regexRules.forEach(rule => rule.id ??= crypto.randomUUID());
|
||||||
|
settings.store.stringRules.forEach(rule => rule.id ??= crypto.randomUUID());
|
||||||
|
},
|
||||||
|
|
||||||
onBeforeMessageSend(channelId, msg) {
|
onBeforeMessageSend(channelId, msg) {
|
||||||
// Channel used for sharing rules, applying rules here would be messy
|
// Channel used for sharing rules, applying rules here would be messy
|
||||||
if (channelId === TEXT_REPLACE_RULES_CHANNEL_ID) return;
|
if (channelId === TEXT_REPLACE_RULES_CHANNEL_ID) return;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue