mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: alter some select option editor bloc events and add tests (#1264)
* chore: separate select and unselect events * style: improve readability * chore: don't send empty payloads if we can help it * test: add select option text field test * test: complete bloc test for select option * test: delete all options between each test * fix: keep insert order * test: combine select and unselect tests * chore: remove duplicate wait Co-authored-by: appflowy <annie@appflowy.io>
This commit is contained in:
@ -261,9 +261,15 @@ class _SelectOptionCellState extends State<_SelectOptionCell> {
|
||||
child: SelectOptionTagCell(
|
||||
option: widget.option,
|
||||
onSelected: (option) {
|
||||
context
|
||||
.read<SelectOptionCellEditorBloc>()
|
||||
.add(SelectOptionEditorEvent.selectOption(option.id));
|
||||
if (widget.isSelected) {
|
||||
context
|
||||
.read<SelectOptionCellEditorBloc>()
|
||||
.add(SelectOptionEditorEvent.unSelectOption(option.id));
|
||||
} else {
|
||||
context
|
||||
.read<SelectOptionCellEditorBloc>()
|
||||
.add(SelectOptionEditorEvent.selectOption(option.id));
|
||||
}
|
||||
},
|
||||
children: [
|
||||
if (widget.isSelected)
|
||||
|
@ -96,7 +96,7 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
|
||||
}
|
||||
|
||||
if (text.isNotEmpty) {
|
||||
widget.onSubmitted(text);
|
||||
widget.onSubmitted(text.trim());
|
||||
focusNode.requestFocus();
|
||||
}
|
||||
},
|
||||
@ -132,26 +132,25 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
|
||||
return;
|
||||
}
|
||||
|
||||
final trimmedText = text.trim();
|
||||
final trimmedText = text.trimLeft();
|
||||
List<String> splits = [];
|
||||
String currentString = '';
|
||||
|
||||
// split the string into tokens
|
||||
for (final char in trimmedText.split('')) {
|
||||
if (!widget.textSeparators.contains(char)) {
|
||||
currentString += char;
|
||||
if (widget.textSeparators.contains(char)) {
|
||||
if (currentString.isNotEmpty) {
|
||||
splits.add(currentString.trim());
|
||||
}
|
||||
currentString = '';
|
||||
continue;
|
||||
}
|
||||
if (currentString.isNotEmpty) {
|
||||
splits.add(currentString);
|
||||
}
|
||||
currentString = '';
|
||||
currentString += char;
|
||||
}
|
||||
// add the remainder (might be '')
|
||||
splits.add(currentString);
|
||||
|
||||
final submittedOptions =
|
||||
splits.sublist(0, splits.length - 1).map((e) => e.trim()).toList();
|
||||
final submittedOptions = splits.sublist(0, splits.length - 1).toList();
|
||||
|
||||
final remainder = splits.elementAt(splits.length - 1).trimLeft();
|
||||
editingController.text = remainder;
|
||||
|
Reference in New Issue
Block a user