From ca7503b30b4ca646b44af345a669941a34d69eca Mon Sep 17 00:00:00 2001 From: Brian Quirt Date: Wed, 5 Mar 2025 09:09:40 -0500 Subject: [PATCH 1/2] Added the ability to dismiss the keyboard --- commet/lib/ui/atoms/dismiss_keyboard.dart | 20 ++++++++++++++++++++ commet/lib/ui/atoms/keyboard_adaptor.dart | 10 ++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 commet/lib/ui/atoms/dismiss_keyboard.dart 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))); } } From d1c7db60ff74b40ab049a3f97fe4ef8341137c1f Mon Sep 17 00:00:00 2001 From: Brian Quirt Date: Sat, 8 Mar 2025 10:32:20 -0500 Subject: [PATCH 2/2] With a hardware keyboard, shift-return will now enter a newline without sending --- commet/lib/ui/molecules/message_input.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/commet/lib/ui/molecules/message_input.dart b/commet/lib/ui/molecules/message_input.dart index 42922978b..28775caa3 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; }