Skip to content

Commit 090cd7f

Browse files
committed
fix: append or replace text in input instead of submit
1 parent bce0e27 commit 090cd7f

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/components/svg/svg_editor.tsx

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,25 @@ function AtomLabelEditForm(props: AtomLabelEditFormProps) {
256256
};
257257
}, []);
258258

259+
function onShortcut(event: MouseEvent<HTMLButtonElement>) {
260+
event.preventDefault();
261+
event.stopPropagation();
262+
263+
if (!formRef.current) return;
264+
const form = formRef.current;
265+
const input = form.querySelector('input[type="text"]') as HTMLInputElement;
266+
if (!input) return;
267+
268+
const value = event.currentTarget.textContent.trim();
269+
input.setRangeText(
270+
value,
271+
input.selectionStart ?? 0,
272+
input.selectionEnd ?? input.value.length,
273+
'end',
274+
);
275+
input.focus();
276+
}
277+
259278
return (
260279
<form
261280
ref={formRef}
@@ -308,12 +327,7 @@ function AtomLabelEditForm(props: AtomLabelEditFormProps) {
308327
key={charName}
309328
type="submit"
310329
style={{ gridArea: charName }}
311-
onClick={(event) => {
312-
event.preventDefault();
313-
event.stopPropagation();
314-
315-
onSubmit(greekChar);
316-
}}
330+
onClick={onShortcut}
317331
>
318332
{greekChar}
319333
</button>
@@ -324,12 +338,7 @@ function AtomLabelEditForm(props: AtomLabelEditFormProps) {
324338
key={primeName}
325339
type="submit"
326340
style={{ gridArea: primeName }}
327-
onClick={(event) => {
328-
event.preventDefault();
329-
event.stopPropagation();
330-
331-
onSubmit(primeChar);
332-
}}
341+
onClick={onShortcut}
333342
>
334343
{primeChar}
335344
</button>

0 commit comments

Comments
 (0)