fix: ctrl + enter in forms, close #362

This commit is contained in:
Xylight committed 2024-07-20 11:49:05 -07:00
1 parent b7e503ae4f
commit 5ea1f2e0cf
2 files changed
+11 -3

No files matched your search

@@ -17,7 +17,10 @@
export let rows: number = 7
export let placeholder: string | undefined = undefined
const dispatch = createEventDispatcher<{ comment: CommentResponse }>()
const dispatch = createEventDispatcher<{
comment: CommentResponse
confirm: string
}>()
export let value = ''
export let actions = true
@@ -76,6 +79,7 @@
on:confirm={() => {
if (actions) {
submit()
dispatch('confirm', value)
}
}}
on:focus
@@ -105,7 +105,11 @@
KeyS: () => wrapSelection('~~', '~~'),
KeyH: () => wrapSelection('\n# ', ''),
KeyK: () => wrapSelection('[](', ')'),
Enter: () => dispatcher('confirm', value),
Enter: (e: any) => {
dispatcher('confirm', value)
const newEvent = new Event('submit', { cancelable: true })
e.target.form.dispatchEvent(newEvent)
},
}
</script>
@@ -295,7 +299,7 @@ overflow-hidden transition-colors"
let shortcut = shortcuts[e.code]
if (shortcut) {
e.preventDefault()
shortcut?.()
shortcut?.(e)
}
}
}}