Skip to content

Commit

Permalink
fix: Fixes the missed auto-space after selecting a word from suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaegel committed May 23, 2024
1 parent 0e72fef commit f3b3e89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
14 changes: 5 additions & 9 deletions lib/domain/todo/todo_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,18 @@ class Todo extends Equatable {
priority: priority,
completionDate: completionDate,
creationDate: creationDate,
description: description != null ? _trim(description) : description,
description: description != null
? description.replaceAllMapped(RegExp(r'\s{2,}'), (match) => ' ')
: description,
);
}

factory Todo.fromString({
String? id,
required String value,
}) {
final todoStr = _trim(value);
final todoStr =
value.trim().replaceAllMapped(RegExp(r'\s{2,}'), (match) => ' ');

bool completion = _str2completion(
_todoStringElementAt(todoStr, 0),
Expand Down Expand Up @@ -559,13 +562,6 @@ class Todo extends Equatable {
}
}

static String _trim(String value) {
// Trim duplicate whitespaces.
return value.trim().replaceAllMapped(RegExp(r'\s{2,}'), (match) {
return ' ';
});
}

static String _todoStringElementAt(String value, int index) {
final List<String> todoStrSplitted = value.split(' ');
try {
Expand Down
10 changes: 7 additions & 3 deletions lib/presentation/filter/states/filter_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class FilterCubit extends Cubit<FilterState> {
/// Regular filter (saved filter)
///
Future<void> create(Filter filter) async {
Future<void> create(Filter f) async {
try {
final Filter filter = f.copyWith(name: f.name.trim());
int id = await _filterRepository.insert(filter);
if (id > 0) {
emit(state.save(filter: filter.copyWith(id: id)));
Expand All @@ -60,8 +61,9 @@ class FilterCubit extends Cubit<FilterState> {
}
}

Future<void> update(Filter filter) async {
Future<void> update(Filter f) async {
try {
final Filter filter = f.copyWith(name: f.name.trim());
int id = await _filterRepository.update(filter);
if (id > 0) {
emit(state.save(filter: filter));
Expand All @@ -85,7 +87,9 @@ class FilterCubit extends Cubit<FilterState> {
void updateName(String name) {
try {
emit(state.update(
filter: state.filter.copyWith(name: name.trim()),
filter: state.filter.copyWith(
name: name.replaceAllMapped(RegExp(r'\s{2,}'), (match) => ' '),
),
));
} on Exception catch (e) {
emit(state.error(message: e.toString()));
Expand Down
15 changes: 9 additions & 6 deletions lib/presentation/todo/states/todo_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ class TodoCubit extends Cubit<TodoState> {
emit(
state.success(
todo: state.todo.copyWith(
description:
state.todo.description.replaceAll(Todo.fmtProject(project), ''),
description: state.todo.description
.replaceAll(Todo.fmtProject(project), '')
.trim(),
),
),
);
Expand Down Expand Up @@ -200,8 +201,9 @@ class TodoCubit extends Cubit<TodoState> {
emit(
state.success(
todo: state.todo.copyWith(
description:
state.todo.description.replaceAll(Todo.fmtContext(context), ''),
description: state.todo.description
.replaceAll(Todo.fmtContext(context), '')
.trim(),
),
),
);
Expand Down Expand Up @@ -296,8 +298,9 @@ class TodoCubit extends Cubit<TodoState> {
emit(
state.success(
todo: state.todo.copyWith(
description:
state.todo.description.replaceAll(Todo.fmtKeyValue(kv), ''),
description: state.todo.description
.replaceAll(Todo.fmtKeyValue(kv), '')
.trim(),
),
),
);
Expand Down

0 comments on commit f3b3e89

Please sign in to comment.