diff --git a/src/components/PostEditor/PostContent.tsx b/src/components/PostEditor/PostContent.tsx index ab12512..4db424b 100644 --- a/src/components/PostEditor/PostContent.tsx +++ b/src/components/PostEditor/PostContent.tsx @@ -38,13 +38,10 @@ export default function PostContent({ const [mentions, setMentions] = useState([]) const canPost = !!text && !posting && !uploadingFiles - const post = async (e: React.MouseEvent) => { - e.stopPropagation() + const post = async (e?: React.MouseEvent) => { + e?.stopPropagation() checkLogin(async () => { - if (!canPost) { - close() - return - } + if (!canPost) return setPosting(true) try { @@ -105,6 +102,7 @@ export default function PostContent({ setText={setText} defaultContent={defaultContent} parentEvent={parentEvent} + onSubmit={() => post()} /> void @@ -28,8 +28,9 @@ const PostTextarea = forwardRef< setText: Dispatch> defaultContent?: string parentEvent?: Event + onSubmit?: () => void } ->(({ text = '', setText, defaultContent, parentEvent }, ref) => { +>(({ text = '', setText, defaultContent, parentEvent, onSubmit }, ref) => { const { t } = useTranslation() const { setUploadingFiles } = usePostEditor() const editor = useEditor({ @@ -54,6 +55,15 @@ const PostTextarea = forwardRef< attributes: { class: 'border rounded-lg p-3 min-h-52 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring' + }, + handleKeyDown: (_view, event) => { + // Handle Ctrl+Enter or Cmd+Enter for submit + if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') { + event.preventDefault() + onSubmit?.() + return true + } + return false } }, content: postContentCache.getPostCache({ defaultContent, parentEvent }),