diff --git a/commet/lib/ui/atoms/dismiss_keyboard.dart b/commet/lib/ui/atoms/dismiss_keyboard.dart new file mode 100644 index 000000000..131b94825 --- /dev/null +++ b/commet/lib/ui/atoms/dismiss_keyboard.dart @@ -0,0 +1,20 @@ +import 'package:flutter/material.dart'; + +class DismissKeyboard extends StatelessWidget { + final Widget child; + const DismissKeyboard({Key? key, required this.child}) : super(key: key); + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: () { + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus && + currentFocus.focusedChild != null) { + FocusManager.instance.primaryFocus?.unfocus(); + } + }, + child: child, + ); + } +} diff --git a/commet/lib/ui/atoms/keyboard_adaptor.dart b/commet/lib/ui/atoms/keyboard_adaptor.dart index a47ac9f16..1c9169827 100644 --- a/commet/lib/ui/atoms/keyboard_adaptor.dart +++ b/commet/lib/ui/atoms/keyboard_adaptor.dart @@ -1,5 +1,6 @@ import 'dart:math'; +import 'package:commet/ui/atoms/dismiss_keyboard.dart'; import 'package:commet/ui/atoms/scaled_safe_area.dart'; import 'package:commet/utils/scaled_app.dart'; import 'package:flutter/material.dart'; @@ -14,9 +15,10 @@ class KeyboardAdaptor extends StatelessWidget { var scaledQuery = MediaQuery.of(context).scale(); var offset = max(scaledQuery.viewInsets.bottom, scaledQuery.padding.bottom); - return ScaledSafeArea( - bottom: false, - child: Padding( - padding: EdgeInsets.fromLTRB(0, 0, 0, offset), child: child)); + return DismissKeyboard( + child: ScaledSafeArea( + bottom: false, + child: Padding( + padding: EdgeInsets.fromLTRB(0, 0, 0, offset), child: child))); } } diff --git a/commet/lib/ui/molecules/message_input.dart b/commet/lib/ui/molecules/message_input.dart index 40c951020..b5f4adb57 100644 --- a/commet/lib/ui/molecules/message_input.dart +++ b/commet/lib/ui/molecules/message_input.dart @@ -315,6 +315,15 @@ class MessageInputState extends State { } if (HardwareKeyboard.instance.isShiftPressed) { + String text = controller.text; + TextSelection textSelection = controller.selection; + String newText = + text.replaceRange(textSelection.start, textSelection.end, "\n"); + controller.text = newText; + controller.selection = textSelection.copyWith( + baseOffset: textSelection.start + 1, + extentOffset: textSelection.start + 1, + ); return KeyEventResult.ignored; }