11import AvatarButtonWithIcon from '@components/AvatarButtonWithIcon' ;
22import FormProvider from '@components/Form/FormProvider' ;
33import InputWrapper from '@components/Form/InputWrapper' ;
4- import type { FormOnyxValues } from '@components/Form/types' ;
4+ import type { FormOnyxValues , FormRef } from '@components/Form/types' ;
55import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator' ;
66import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
77import ScreenWrapper from '@components/ScreenWrapper' ;
@@ -37,6 +37,8 @@ import type NewAgentTemplate from '@src/types/onyx/NewAgentTemplate';
3737import type { Errors } from '@src/types/onyx/OnyxCommon' ;
3838import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue' ;
3939
40+ import type { TextInputKeyPressEvent } from 'react-native' ;
41+
4042import React , { useCallback , useEffect , useRef } from 'react' ;
4143import { View } from 'react-native' ;
4244
@@ -63,6 +65,18 @@ function AddAgentPageContent({route, template}: AddAgentPageContentProps) {
6365 const [ avatarDraft , avatarDraftMetadata ] = useOnyx ( ONYXKEYS . AGENT_NEW_AVATAR_DRAFT ) ;
6466 const isDraftLoading = isLoadingOnyxValue ( avatarDraftMetadata ) ;
6567 const hasSubmittedRef = useRef ( false ) ;
68+ const formRef = useRef < FormRef > ( null ) ;
69+
70+ const submitFormOnModEnter = ( event : TextInputKeyPressEvent | KeyboardEvent ) => {
71+ if ( ! ( 'key' in event ) ) {
72+ return ;
73+ }
74+ if ( event . key === 'Enter' && ( event . metaKey || event . ctrlKey ) ) {
75+ // The markdown input inserts a line break for any Enter keydown whose default is not already prevented, so the submit combo has to claim it first.
76+ event . preventDefault ( ) ;
77+ formRef . current ?. submit ( ) ;
78+ }
79+ } ;
6680
6781 const uploadedAvatar = avatarDraft ?. uploadedAvatar ;
6882 const selectedPresetID = avatarDraft ?. customExpensifyAvatarID && AGENT_AVATARS . isAvatarID ( avatarDraft . customExpensifyAvatarID ) ? avatarDraft . customExpensifyAvatarID : undefined ;
@@ -150,6 +164,7 @@ function AddAgentPageContent({route, template}: AddAgentPageContentProps) {
150164 onBackButtonPress = { ( ) => Navigation . goBack ( ROUTES . SETTINGS_AGENTS_NEW . getRoute ( policyID ? { policyID} : undefined ) ) }
151165 />
152166 < FormProvider
167+ ref = { formRef }
153168 formID = { ONYXKEYS . FORMS . ADD_AGENT_FORM }
154169 onSubmit = { handleSubmit }
155170 validate = { validate }
@@ -192,6 +207,9 @@ function AddAgentPageContent({route, template}: AddAgentPageContentProps) {
192207 label = { translate ( 'addAgentPage.instructions' ) }
193208 accessibilityLabel = { translate ( 'addAgentPage.instructions' ) }
194209 role = { CONST . ROLE . PRESENTATION }
210+ type = "markdown"
211+ excludedMarkdownStyles = { [ 'mentionReport' ] }
212+ onKeyPress = { submitFormOnModEnter }
195213 defaultValue = { defaultPrompt }
196214 multiline
197215 containerStyles = { [ styles . flex1 ] }
0 commit comments