Submit comments on ctrl/cmd-enter

This commit is contained in:
Austin Chen 2022-08-31 21:44:13 -07:00
parent bc1ec414de
commit 9bd7fe5905
2 changed files with 7 additions and 7 deletions

View File

@ -384,6 +384,7 @@ export function CommentInput(props: {
user={user} user={user}
submitComment={submitComment} submitComment={submitComment}
isSubmitting={isSubmitting} isSubmitting={isSubmitting}
submitOn={'mod-enter'}
presetId={id} presetId={id}
/> />
</div> </div>
@ -398,7 +399,8 @@ export function CommentInputTextArea(props: {
upload: Parameters<typeof TextEditor>[0]['upload'] upload: Parameters<typeof TextEditor>[0]['upload']
submitComment: (id?: string) => void submitComment: (id?: string) => void
isSubmitting: boolean isSubmitting: boolean
submitOnEnter?: boolean // mod-enter = ctrl-enter or cmd-enter
submitOn?: 'enter' | 'mod-enter'
presetId?: string presetId?: string
}) { }) {
const { const {
@ -408,11 +410,9 @@ export function CommentInputTextArea(props: {
submitComment, submitComment,
presetId, presetId,
isSubmitting, isSubmitting,
submitOnEnter, submitOn,
replyToUser, replyToUser,
} = props } = props
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])
@ -431,10 +431,10 @@ export function CommentInputTextArea(props: {
editorProps: { editorProps: {
handleKeyDown: (view, event) => { handleKeyDown: (view, event) => {
if ( if (
submitOnEnter && submitOn &&
event.key === 'Enter' && event.key === 'Enter' &&
!event.shiftKey && !event.shiftKey &&
(!isMobile || event.ctrlKey || event.metaKey) && (submitOn === 'enter' || event.ctrlKey || event.metaKey) &&
// mention list is closed // mention list is closed
!(view.state as any).mention$.active !(view.state as any).mention$.active
) { ) {

View File

@ -175,7 +175,7 @@ export function GroupChat(props: {
replyToUser={replyToUser} replyToUser={replyToUser}
submitComment={submitMessage} submitComment={submitMessage}
isSubmitting={isSubmitting} isSubmitting={isSubmitting}
submitOnEnter submitOn={'enter'}
/> />
</div> </div>
</div> </div>