diff --git a/src/lib/components/editor/Editor.svelte b/src/lib/components/editor/Editor.svelte index 7c63368..5d731a7 100644 --- a/src/lib/components/editor/Editor.svelte +++ b/src/lib/components/editor/Editor.svelte @@ -52,15 +52,15 @@ withdrawal: "withdrawal", }; const FIELDS: [string, string, string][] = [ - ["alt+d", "description", "description"], - ["alt+f", "source", "source account"], - ["alt+t", "destination", "destination account"], - ["alt+w", "date", "date"], - ["alt+m", "amount", "amount"], - ["alt+k", "category", "category"], - ["alt+b", "budget", "budget"], - ["alt+g", "tags", "tags"], - ["alt+r", "notes", "notes"], + ["d", "description", "description"], + ["f", "source", "source account"], + ["t", "destination", "destination account"], + ["w", "date", "date"], + ["m", "amount", "amount"], + ["c", "category", "category"], + ["b", "budget", "budget"], + ["#", "tags", "tags"], + ["r", "notes", "notes"], ]; const INLINE = new Set([ "description", @@ -104,6 +104,7 @@ const originalType = start.type; let form = $state
(start); + let lastSplit = start.splits[0].key; let saved = $state(untrack(() => group)); let snapshot = JSON.stringify(start); let errors = $state({}); @@ -204,9 +205,17 @@ tick().then(() => focusField("description", false)); }); + function splitOf(target: EventTarget | null): number | null { + const holder = + target instanceof Element ? target.closest("[data-split]") : null; + return holder ? Number(holder.getAttribute("data-split")) : null; + } + function currentKey(): number { - const holder = document.activeElement?.closest("[data-split]"); - return Number(holder?.getAttribute("data-split") ?? form.splits[0].key); + const key = splitOf(document.activeElement) ?? lastSplit; + return form.splits.some((split) => split.key === key) + ? key + : form.splits[0].key; } function focusField(field: string, select = true) { @@ -452,29 +461,25 @@ }, { group: "Editor", - input: true, - keys: "mod+alt+Backspace", + keys: "X", label: "Remove the current split", run: () => removeSplit(), }, ...TX_TYPES.map((type, index) => ({ group: "Editor", - input: true, - keys: `alt+${index + 1}`, + keys: `${index + 1}`, label: `Make it a ${type}`, run: () => setType(type), })), ...FIELDS.map(([keys, field, label]) => ({ group: "Editor", - input: true, keys, label: `Go to ${label}`, run: () => focusField(field), })), { group: "Editor", - input: true, - keys: "alt+i", + keys: "T", label: "Go to the split transaction title", run: () => document.getElementById("group-title")?.focus(), }, @@ -520,7 +525,11 @@ {/snippet} -
+
(lastSplit = splitOf(event.target) ?? lastSplit)} + bind:this={root} +>
{TYPE_LABEL[type]} - + {/each}
@@ -614,7 +621,7 @@ Remove split - + {/if} {/snippet} @@ -216,7 +213,7 @@ - {@render account("source", "Source account", "alt+f")} - {@render account("destination", "Destination account", "alt+t")} + {@render account("source", "Source account", "f")} + {@render account("destination", "Destination account", "t")} {#if first} - +