diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index c1ffb8627..40a1c3f7e 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -696,6 +696,7 @@ } } }, + "checkList": "Check list", "countParticipants": "{count} participants", "@countParticipants": { "type": "String", diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 1103c47fa..dd1d16c91 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -275,13 +275,44 @@ class ChatController extends State ); } - KeyEventResult _shiftEnterKeyHandling(FocusNode node, KeyEvent evt) { + KeyEventResult _customEnterKeyHandling(FocusNode node, KeyEvent evt) { if (!HardwareKeyboard.instance.isShiftPressed && - evt.logicalKey.keyLabel == 'Enter') { + evt.logicalKey.keyLabel == 'Enter' && + (AppConfig.sendOnEnter ?? !PlatformInfos.isMobile)) { if (evt is KeyDownEvent) { send(); } return KeyEventResult.handled; + } else if (evt.logicalKey.keyLabel == 'Enter' && evt is KeyDownEvent) { + final currentLineNum = sendController.text + .substring( + 0, + sendController.selection.baseOffset, + ) + .split('\n') + .length - + 1; + final currentLine = sendController.text.split('\n')[currentLineNum]; + + for (final pattern in [ + '- [ ] ', + '- [x] ', + '* [ ] ', + '* [x] ', + '- ', + '* ', + '+ ', + ]) { + if (currentLine.startsWith(pattern)) { + if (currentLine == pattern) { + return KeyEventResult.ignored; + } + sendController.text += '\n$pattern'; + return KeyEventResult.handled; + } + } + + return KeyEventResult.ignored; } else { return KeyEventResult.ignored; } @@ -289,11 +320,7 @@ class ChatController extends State @override void initState() { - inputFocus = FocusNode( - onKeyEvent: (AppConfig.sendOnEnter ?? !PlatformInfos.isMobile) - ? _shiftEnterKeyHandling - : null, - ); + inputFocus = FocusNode(onKeyEvent: _customEnterKeyHandling); scrollController.addListener(_updateScrollController); inputFocus.addListener(_inputFocusListener); @@ -1154,6 +1181,14 @@ class ChatController extends State if (choice == 'location') { sendLocationAction(); } + if (choice == 'checklist') { + if (sendController.text.isEmpty) { + sendController.text = '- [ ] '; + } else { + sendController.text += '\n- [ ] '; + } + inputFocus.requestFocus(); + } } unpinEvent(String eventId) async { diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index 88860a77e..b07d2ae38 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -123,6 +123,18 @@ class ChatInputRow extends StatelessWidget { onSelected: controller.onAddPopupMenuButtonSelected, itemBuilder: (BuildContext context) => >[ + PopupMenuItem( + value: 'checklist', + child: ListTile( + leading: CircleAvatar( + backgroundColor: theme.colorScheme.onPrimaryContainer, + foregroundColor: theme.colorScheme.primaryContainer, + child: const Icon(Icons.check_circle_outlined), + ), + title: Text(L10n.of(context).checkList), + contentPadding: const EdgeInsets.all(0), + ), + ), if (PlatformInfos.isMobile) PopupMenuItem( value: 'location',