Skip to content

Commit

Permalink
[text-replacements] fix first regex not editable
Browse files Browse the repository at this point in the history
  • Loading branch information
ioj4 authored and yellowsink committed Mar 26, 2024
1 parent 8dca564 commit 8d2ae7d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions plugins/text-replacements/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const { store } = shelter.plugin;

const openEditDialog = (idx?: number) =>
openModal((props) => {
const initial = idx ? store.regexes[idx]: ["", "", "gi", ""];
const isAdd = isNaN(idx);
const initial = isAdd ? ["", "", "gi", ""] : store.regexes[idx];
const [name, setName] = createSignal<string>(initial[0]);
const [regexp, setRegexp] = createSignal<string>(initial[1]);
const [flags, setFlags] = createSignal<string>(initial[2]);
Expand All @@ -36,7 +37,7 @@ const openEditDialog = (idx?: number) =>
return (
<ModalRoot size={ModalSizes.MEDIUM}>
<ModalHeader close={props.close}>
{idx ? "Editing" : "Adding"} "{name()}"
{isAdd ? "Adding" : "Editing"} "{name()}"
</ModalHeader>
<ModalBody>
<Header tag={HeaderTags.H3}>Name</Header>
Expand Down Expand Up @@ -68,10 +69,10 @@ const openEditDialog = (idx?: number) =>
close={props.close}
onConfirm={() => {
const newRegex = [name(), regexp(), flags(), replace()];
if (idx) {
store.regexes[idx] = newRegex;
} else {
if (isAdd) {
store.regexes.push(newRegex);
} else {
store.regexes[idx] = newRegex;
}
// save!
store.regexes = store.regexes;
Expand Down

0 comments on commit 8d2ae7d

Please sign in to comment.