@@ -185,12 +185,15 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
185
185
onChanged: _onChanged,
186
186
onSubmitted: (inputText) {
187
187
if (sendMessageConfig? .onSubmitted != null ) {
188
+ widget.onPressed ();
189
+ _inputText.value = '' ;
188
190
sendMessageConfig! .onSubmitted !(inputText);
189
191
} else {
190
192
_onSubmitted (inputText);
191
193
}
192
194
},
193
- textInputAction: textFieldConfig? .textInputAction ?? TextInputAction .newline,
195
+ textInputAction: textFieldConfig? .textInputAction ??
196
+ TextInputAction .unspecified,
194
197
enabled: textFieldConfig? .enabled,
195
198
textCapitalization: textFieldConfig? .textCapitalization ??
196
199
TextCapitalization .sentences,
@@ -386,21 +389,24 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
386
389
return kIsWeb || Platform .isMacOS || Platform .isWindows || Platform .isLinux;
387
390
}
388
391
389
- void _onSubmitted (String inputText){
392
+ void _onSubmitted (String inputText) {
390
393
bool isShiftPressed = HardwareKeyboard .instance.isShiftPressed;
391
- if (_isWebOrDesktop () && isShiftPressed){
392
- widget.textEditingController.text += '\n ' ;
394
+ if (_isWebOrDesktop () && isShiftPressed) {
395
+ final controller = widget.textEditingController;
396
+ final text = controller.text;
397
+ final cursorPosition = controller.selection.baseOffset;
398
+ final newText = '${text .substring (0 , cursorPosition )}\n ${text .substring (cursorPosition )}' ;
399
+ controller.text = newText;
400
+ // Move cursor to the correct position after the newline
393
401
WidgetsBinding .instance.addPostFrameCallback ((_) {
394
- widget.textEditingController .selection = TextSelection .fromPosition (
395
- TextPosition (offset: widget.textEditingController.text.length ),
402
+ controller .selection = TextSelection .fromPosition (
403
+ TextPosition (offset: cursorPosition + 1 ),
396
404
);
397
405
widget.focusNode.requestFocus ();
398
406
});
399
- }else {
400
- if (inputText.isNotEmpty){
401
- widget.onPressed ();
402
- _inputText.value = '' ;
403
- }
407
+ } else if (inputText.isNotEmpty) {
408
+ widget.onPressed ();
409
+ _inputText.value = '' ;
404
410
}
405
411
}
406
412
0 commit comments