mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 10:57:04 +00:00
Handle escape in chat
This commit is contained in:
@@ -18,11 +18,12 @@
|
|||||||
url?: string
|
url?: string
|
||||||
h?: string
|
h?: string
|
||||||
content?: string
|
content?: string
|
||||||
|
onEscape?: () => void
|
||||||
onEditPrevious?: () => void
|
onEditPrevious?: () => void
|
||||||
onSubmit: (event: EventContent) => void
|
onSubmit: (event: EventContent) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const {url, h, content, onEditPrevious, onSubmit}: Props = $props()
|
const {url, h, content, onEscape, onEditPrevious, onSubmit}: Props = $props()
|
||||||
|
|
||||||
const autofocus = !isMobile
|
const autofocus = !isMobile
|
||||||
|
|
||||||
@@ -34,6 +35,10 @@
|
|||||||
editor.then(ed => ed.getText({blockSeparator: "\n"}) === "")
|
editor.then(ed => ed.getText({blockSeparator: "\n"}) === "")
|
||||||
|
|
||||||
const handleKeyDown = async (event: KeyboardEvent) => {
|
const handleKeyDown = async (event: KeyboardEvent) => {
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
onEscape?.()
|
||||||
|
}
|
||||||
|
|
||||||
if (event.key === "ArrowUp" && (await canEnterEditPrevious())) {
|
if (event.key === "ArrowUp" && (await canEnterEditPrevious())) {
|
||||||
onEditPrevious?.()
|
onEditPrevious?.()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -280,6 +280,12 @@
|
|||||||
cleanup = feed.cleanup
|
cleanup = feed.cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onEscape = () => {
|
||||||
|
clearParent()
|
||||||
|
clearShare()
|
||||||
|
eventToEdit = undefined
|
||||||
|
}
|
||||||
|
|
||||||
const canEditEvent = (event: TrustedEvent) =>
|
const canEditEvent = (event: TrustedEvent) =>
|
||||||
event.pubkey === $pubkey && event.created_at >= ago(5, MINUTE)
|
event.pubkey === $pubkey && event.created_at >= ago(5, MINUTE)
|
||||||
|
|
||||||
@@ -492,6 +498,7 @@
|
|||||||
{url}
|
{url}
|
||||||
{h}
|
{h}
|
||||||
{onSubmit}
|
{onSubmit}
|
||||||
|
{onEscape}
|
||||||
{onEditPrevious}
|
{onEditPrevious}
|
||||||
content={eventToEdit?.content}
|
content={eventToEdit?.content}
|
||||||
bind:this={compose} />
|
bind:this={compose} />
|
||||||
|
|||||||
@@ -188,6 +188,12 @@
|
|||||||
return elements
|
return elements
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const onEscape = () => {
|
||||||
|
clearParent()
|
||||||
|
clearShare()
|
||||||
|
eventToEdit = undefined
|
||||||
|
}
|
||||||
|
|
||||||
const canEditEvent = (event: TrustedEvent) =>
|
const canEditEvent = (event: TrustedEvent) =>
|
||||||
event.pubkey === $pubkey && event.created_at >= ago(5, MINUTE)
|
event.pubkey === $pubkey && event.created_at >= ago(5, MINUTE)
|
||||||
|
|
||||||
@@ -315,6 +321,7 @@
|
|||||||
<RoomCompose
|
<RoomCompose
|
||||||
{url}
|
{url}
|
||||||
{onSubmit}
|
{onSubmit}
|
||||||
|
{onEscape}
|
||||||
{onEditPrevious}
|
{onEditPrevious}
|
||||||
content={eventToEdit?.content}
|
content={eventToEdit?.content}
|
||||||
bind:this={compose} />
|
bind:this={compose} />
|
||||||
|
|||||||
Reference in New Issue
Block a user