feat: add shortcut key support for posting
This commit is contained in:
parent
8beb2430b2
commit
bf7bb286af
2 changed files with 16 additions and 8 deletions
|
|
@ -11,11 +11,11 @@ import { EditorContent, useEditor } from '@tiptap/react'
|
|||
import { Event } from 'nostr-tools'
|
||||
import { Dispatch, forwardRef, SetStateAction, useImperativeHandle } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { usePostEditor } from '../PostEditorProvider'
|
||||
import CustomMention from './CustomMention'
|
||||
import { FileHandler } from './FileHandler'
|
||||
import Preview from './Preview'
|
||||
import suggestion from './suggestion'
|
||||
import { usePostEditor } from '../PostEditorProvider'
|
||||
|
||||
export type TPostTextareaHandle = {
|
||||
appendText: (text: string) => void
|
||||
|
|
@ -28,8 +28,9 @@ const PostTextarea = forwardRef<
|
|||
setText: Dispatch<SetStateAction<string>>
|
||||
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 }),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue