feat: Create lists with checkboxes via + menu
This commit is contained in:
parent
a2e5a940bd
commit
9da7a5704e
3 changed files with 55 additions and 7 deletions
|
|
@ -696,6 +696,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"checkList": "Check list",
|
||||
"countParticipants": "{count} participants",
|
||||
"@countParticipants": {
|
||||
"type": "String",
|
||||
|
|
|
|||
|
|
@ -275,13 +275,44 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
);
|
||||
}
|
||||
|
||||
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<ChatPageWithRoom>
|
|||
|
||||
@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<ChatPageWithRoom>
|
|||
if (choice == 'location') {
|
||||
sendLocationAction();
|
||||
}
|
||||
if (choice == 'checklist') {
|
||||
if (sendController.text.isEmpty) {
|
||||
sendController.text = '- [ ] ';
|
||||
} else {
|
||||
sendController.text += '\n- [ ] ';
|
||||
}
|
||||
inputFocus.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
unpinEvent(String eventId) async {
|
||||
|
|
|
|||
|
|
@ -123,6 +123,18 @@ class ChatInputRow extends StatelessWidget {
|
|||
onSelected: controller.onAddPopupMenuButtonSelected,
|
||||
itemBuilder: (BuildContext context) =>
|
||||
<PopupMenuEntry<String>>[
|
||||
PopupMenuItem<String>(
|
||||
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<String>(
|
||||
value: 'location',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue