Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions commet/lib/ui/atoms/dismiss_keyboard.dart
Original file line number Diff line number Diff line change
@@ -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,
);
}
}
10 changes: 6 additions & 4 deletions commet/lib/ui/atoms/keyboard_adaptor.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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)));
}
}
9 changes: 9 additions & 0 deletions commet/lib/ui/molecules/message_input.dart
Copy link
Contributor

@Airyzz Airyzz Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code shouldn't be necessary, and the desired behavior was already implemented previously. It seems that the recent change setting keyboardType: TextInputType.text on the TextField prevented the behaviour, which I am correcting in #435

Please remove

Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ class MessageInputState extends State<MessageInput> {
}

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;
}

Expand Down