Re-add submit on enter
This commit is contained in:
parent
d155715900
commit
5a811b417d
|
@ -461,11 +461,39 @@ export function CommentInputTextArea(props: {
|
||||||
isSubmitting,
|
isSubmitting,
|
||||||
replyToUsername,
|
replyToUsername,
|
||||||
} = props
|
} = props
|
||||||
const { width } = useWindowSize()
|
const isMobile = (useWindowSize().width ?? 0) < 768 // TODO: base off input device (keybord vs touch)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
editor?.setEditable(!isSubmitting)
|
editor?.setEditable(!isSubmitting)
|
||||||
}, [isSubmitting, editor])
|
}, [isSubmitting, editor])
|
||||||
|
|
||||||
|
const submit = () => {
|
||||||
|
submitComment(presetId)
|
||||||
|
editor?.commands?.clearContent()
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
editor?.setOptions({
|
||||||
|
editorProps: {
|
||||||
|
handleKeyDown: (view, event) => {
|
||||||
|
if (
|
||||||
|
event.key === 'Enter' &&
|
||||||
|
!event.shiftKey &&
|
||||||
|
(!isMobile || event.ctrlKey || event.metaKey) &&
|
||||||
|
// mention list is closed
|
||||||
|
!(view.state as any).mention$.active
|
||||||
|
) {
|
||||||
|
submit()
|
||||||
|
event.preventDefault()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [editor])
|
||||||
|
|
||||||
// TODO: make at mention show up at beginning
|
// TODO: make at mention show up at beginning
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -479,10 +507,7 @@ export function CommentInputTextArea(props: {
|
||||||
(!editor || editor.isEmpty) &&
|
(!editor || editor.isEmpty) &&
|
||||||
'pointer-events-none text-gray-500'
|
'pointer-events-none text-gray-500'
|
||||||
)}
|
)}
|
||||||
onClick={() => {
|
onClick={submit}
|
||||||
submitComment(presetId)
|
|
||||||
editor?.commands.clearContent()
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<PaperAirplaneIcon
|
<PaperAirplaneIcon
|
||||||
className={'m-0 min-w-[22px] rotate-90 p-0 '}
|
className={'m-0 min-w-[22px] rotate-90 p-0 '}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user