From 8d2ae7df943a186a6535299b684a08cc92f01c4c Mon Sep 17 00:00:00 2001 From: ioj4 <69911332+ioj4@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:19:15 +0100 Subject: [PATCH] [text-replacements] fix first regex not editable --- plugins/text-replacements/settings.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/text-replacements/settings.tsx b/plugins/text-replacements/settings.tsx index 67d0614..cefb5fd 100644 --- a/plugins/text-replacements/settings.tsx +++ b/plugins/text-replacements/settings.tsx @@ -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(initial[0]); const [regexp, setRegexp] = createSignal(initial[1]); const [flags, setFlags] = createSignal(initial[2]); @@ -36,7 +37,7 @@ const openEditDialog = (idx?: number) => return ( - {idx ? "Editing" : "Adding"} "{name()}" + {isAdd ? "Adding" : "Editing"} "{name()}"
Name
@@ -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;