Skip to content

Commit 5d3d16f

Browse files
committed
fix: three ways the app disagreed with itself, found by an end-to-end pass
Walked the whole journey on a device — add with every field, detail edits, search, filters, reports, sync — and fixed what surfaced: 1. A typed-but-unsubmitted tag was silently dropped on save, on both surfaces that edit tags. A tag only enters the committed list on enter, a separator, or a suggestion tap; text still sitting in the field when Save is tapped was invisible to the save path, which then wiped it. Typing "urgent" and hitting Save produced an untagged task that claimed success. The widget now reports its raw text to the parent, and all four save paths (three add-sheet handlers, the detail tag editor) adopt pending text as a final tag — saving is as clear a submission as pressing enter. Also moved the tag-list listener from build() to initState(): it was stacking a new listener on every rebuild. 2. The taskd list had two search implementations that disagreed on case. search() lowercases both sides; the re-filter that runs on every sort or filter change compared raw, so the same query returned different results before and after a refresh. Both lowercase now, matching replica mode. 3. The filter drawer matched project by exact string, so selecting "work" hid "work.sub" tasks — while the report engine, three screens away, already used Taskwarrior's hierarchy rule (dot boundary, so "workshop" stays excluded). The rule is now public on VirtualFilterEngine and the drawer calls it; five tests pin the seam directly. Tested: 422 Dart tests pass (5 new), analyze clean. Verified on device: a tag typed without enter survives save on both surfaces and a re-open; project filtering still works; the report builder's live count, custom-report save to .taskrc, and run all work end to end.
1 parent 77f3dca commit 5d3d16f

7 files changed

Lines changed: 105 additions & 20 deletions

File tree

‎lib/app/modules/home/controllers/home_controller.dart‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,16 @@ class HomeController extends GetxController {
310310
});
311311

312312
searchedTasks.assignAll(queriedTasks);
313-
var searchTerm = searchController.text;
313+
// Lowercase both sides to match search() below — this path re-runs on
314+
// every sort/filter change, and when it was case-sensitive the same query
315+
// returned different results before and after a refresh.
316+
var searchTerm = searchController.text.toLowerCase();
314317
if (searchVisible.value) {
315318
searchedTasks.value = searchedTasks
316319
.where((task) =>
317-
task.description.contains(searchTerm) ||
318-
(task.annotations?.asList() ?? []).any(
319-
(annotation) => annotation.description.contains(searchTerm)))
320+
task.description.toLowerCase().contains(searchTerm) ||
321+
(task.annotations?.asList() ?? []).any((annotation) =>
322+
annotation.description.toLowerCase().contains(searchTerm)))
320323
.toList();
321324
}
322325
pendingTags.value = _pendingTags();

‎lib/app/modules/home/views/add_task_bottom_sheet_new.dart‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,23 @@ class AddTaskBottomSheet extends StatelessWidget {
219219
Widget buildTagsInput(BuildContext context) => AddTaskTagsInput(
220220
suggestions: homeController.allTagsInCurrentTasks,
221221
onTagsChanges: (p0) => homeController.tags.value = p0,
222+
// Mirror the uncommitted field text so save can flush it — a tag only
223+
// enters `tags` on enter or a separator, and text still in the field
224+
// at save time used to be silently thrown away.
225+
onTextChanged: (text) => homeController.tagcontroller.text = text,
222226
);
223227

228+
/// A tag typed but not yet submitted lives only in the text field. Saving is
229+
/// as clear a submission as pressing enter, so adopt it instead of dropping
230+
/// it. Trim is enough: the field splits on space and comma, so pending text
231+
/// can never contain a separator.
232+
void _adoptPendingTag() {
233+
final String pending = homeController.tagcontroller.text.trim();
234+
if (pending.isNotEmpty && !homeController.tags.contains(pending)) {
235+
homeController.tags.add(pending);
236+
}
237+
}
238+
224239
Widget buildDatePicker(BuildContext context) => AddTaskDatePickerInput(
225240
onDateChanges: (List<DateTime?> p0) {
226241
homeController.selectedDates.value = p0;
@@ -321,6 +336,7 @@ class AddTaskBottomSheet extends StatelessWidget {
321336
}
322337

323338
void onSaveButtonClickedTaskC(BuildContext context) async {
339+
_adoptPendingTag();
324340
if (homeController.formKey.currentState!.validate()) {
325341
debugPrint("tags ${homeController.tags}");
326342
var task = TaskForC(
@@ -370,6 +386,7 @@ class AddTaskBottomSheet extends StatelessWidget {
370386
}
371387

372388
void onSaveButtonClicked(BuildContext context) async {
389+
_adoptPendingTag();
373390
if (homeController.formKey.currentState!.validate()) {
374391
try {
375392
var task = taskParser(homeController.namecontroller.text.trim())
@@ -456,6 +473,7 @@ class AddTaskBottomSheet extends StatelessWidget {
456473
}
457474

458475
void onSaveButtonClickedForReplica(BuildContext context) async {
476+
_adoptPendingTag();
459477
if (homeController.formKey.currentState!.validate()) {
460478
try {
461479
final String? error =

‎lib/app/modules/home/views/show_tasks_replica.dart‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:taskwarrior/app/utils/themes/theme_extension.dart';
1111
import 'package:taskwarrior/app/utils/language/sentence_manager.dart';
1212
import 'package:taskwarrior/app/v3/champion/replica.dart';
1313
import 'package:taskwarrior/app/v3/champion/models/task_for_replica.dart';
14+
import 'package:taskwarrior/app/utils/taskchampion/virtual_filter_engine.dart';
1415

1516
class TaskReplicaViewBuilder extends StatelessWidget {
1617
const TaskReplicaViewBuilder({
@@ -41,7 +42,13 @@ class TaskReplicaViewBuilder extends StatelessWidget {
4142
// it must NOT be an Obx (an Obx with no observable read throws ObxError).
4243
List<TaskForReplica> tasks = List<TaskForReplica>.from(replicaTasks);
4344
if (project != null && project!.isNotEmpty && project != 'All Projects') {
44-
tasks = tasks.where((task) => task.project == project).toList();
45+
// Same hierarchy rule as report filters: selecting "work" includes
46+
// "work.sub". An exact match here made the drawer disagree with the
47+
// report engine (and with desktop Taskwarrior) about the same project.
48+
tasks = tasks
49+
.where((task) =>
50+
VirtualFilterEngine.projectMatches(task.project, project!))
51+
.toList();
4552
}
4653
tasks = tasks.where((task) => task.status == statusFilter).toList();
4754

‎lib/app/modules/taskc_details/views/tag_editor.dart‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class TagEditor extends StatelessWidget {
1919
@override
2020
Widget build(BuildContext context) {
2121
final RxList<String> tags = RxList<String>(initialTags);
22+
// The raw field text, mirrored on every keystroke. A tag typed but not
23+
// submitted is invisible in `tags`, and Save used to drop it silently.
24+
String pendingText = '';
2225
return Padding(
2326
padding: EdgeInsets.only(
2427
bottom: MediaQuery.of(context).viewInsets.bottom,
@@ -49,7 +52,14 @@ class TagEditor extends StatelessWidget {
4952
),
5053
TextButton(
5154
onPressed: () {
52-
onSave(tags);
55+
// Saving is as clear a submission as pressing enter, so a
56+
// tag still sitting in the field is adopted, not dropped.
57+
final List<String> result = List<String>.from(tags);
58+
final String pending = pendingText.trim();
59+
if (pending.isNotEmpty && !result.contains(pending)) {
60+
result.add(pending);
61+
}
62+
onSave(result);
5363
Get.back();
5464
},
5565
child: Text(
@@ -68,6 +78,7 @@ class TagEditor extends StatelessWidget {
6878
initialTags: initialTags,
6979
suggestions: suggestions,
7080
onTagsChanges: (newTags) => tags.value = newTags,
81+
onTextChanged: (text) => pendingText = text,
7182
),
7283
),
7384
const Padding(padding: EdgeInsets.all(20)),

‎lib/app/utils/add_task_dialogue/tags_input.dart‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@ class AddTaskTagsInput extends StatefulWidget {
88
final Iterable<String> initialTags;
99
final Function(List<String>)? onTagsChanges;
1010

11+
/// Fires with the raw field text on every keystroke. A tag only enters the
12+
/// committed list on enter, a separator, or a suggestion tap — so text still
13+
/// sitting in the field when the parent saves is invisible through
14+
/// [onTagsChanges] alone, and every caller was silently dropping it. The
15+
/// parent mirrors this and flushes it as a final tag at save time.
16+
final Function(String)? onTextChanged;
17+
1118
const AddTaskTagsInput(
1219
{super.key,
1320
this.suggestions = const Iterable.empty(),
1421
this.initialTags = const Iterable.empty(),
15-
this.onTagsChanges});
22+
this.onTagsChanges,
23+
this.onTextChanged});
1624

1725
@override
1826
_AddTaskTagsInputState createState() => _AddTaskTagsInputState();
@@ -25,6 +33,13 @@ class _AddTaskTagsInputState extends State<AddTaskTagsInput> {
2533
void initState() {
2634
super.initState();
2735
stringTagController = StringTagController();
36+
// Registered once here — this used to happen in build(), which stacked a
37+
// fresh listener on every rebuild.
38+
stringTagController.addListener(() {
39+
if (widget.onTagsChanges != null) {
40+
widget.onTagsChanges!(stringTagController.getTags!);
41+
}
42+
});
2843
}
2944

3045
@override
@@ -36,14 +51,10 @@ class _AddTaskTagsInputState extends State<AddTaskTagsInput> {
3651
@override
3752
Widget build(BuildContext context) {
3853
const paddingX = 12;
39-
stringTagController.addListener(() {
40-
if (widget.onTagsChanges != null) {
41-
widget.onTagsChanges!(stringTagController.getTags!);
42-
}
43-
});
4454
return Autocomplete<String>(
4555
onSelected: (String value) {
4656
stringTagController.onTagSubmitted(value);
57+
widget.onTextChanged?.call('');
4758
},
4859
optionsViewBuilder: (context, onAutoCompleteSelect, options) {
4960
return Align(
@@ -140,8 +151,14 @@ class _AddTaskTagsInputState extends State<AddTaskTagsInput> {
140151
))
141152
: null,
142153
),
143-
onChanged: inputFieldValues.onTagChanged,
144-
onFieldSubmitted: inputFieldValues.onTagSubmitted,
154+
onChanged: (value) {
155+
inputFieldValues.onTagChanged(value);
156+
widget.onTextChanged?.call(value);
157+
},
158+
onFieldSubmitted: (value) {
159+
inputFieldValues.onTagSubmitted(value);
160+
widget.onTextChanged?.call('');
161+
},
145162
);
146163
},
147164
);

‎lib/app/utils/taskchampion/virtual_filter_engine.dart‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,22 @@ class VirtualFilterEngine {
134134
}).toList();
135135
}
136136

137+
/// Taskwarrior's project semantics: [selected] matches its own tasks and its
138+
/// children's ("work" matches "work" and "work.sub"). A raw prefix match
139+
/// would also wrongly match an unrelated sibling like "workshop", so a dot
140+
/// boundary is required after the prefix. Public because the home filter
141+
/// drawer must agree with report filters about what "project = X" means.
142+
static bool projectMatches(String? taskProject, String selected) {
143+
final String proj = taskProject ?? '';
144+
return proj == selected || proj.startsWith('$selected.');
145+
}
146+
137147
static bool _matchAttribute(TaskLike task, String attr, String value) {
138148
switch (attr) {
139149
case 'status':
140150
return (task.status ?? '') == value;
141151
case 'project':
142-
// Taskwarrior treats project as a hierarchy match: "work" matches
143-
// "work" and its children ("work.sub"), but a raw prefix match would
144-
// also wrongly match an unrelated sibling like "workshop" — require a
145-
// dot boundary after the prefix.
146-
final String proj = task.project ?? '';
147-
return proj == value || proj.startsWith('$value.');
152+
return projectMatches(task.project, value);
148153
case 'priority':
149154
return (task.priority ?? '') == value;
150155
default:

‎test/utils/taskchampion/reporting_engine_test.dart‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,30 @@ void main() {
155155
});
156156
});
157157

158+
group('VirtualFilterEngine.projectMatches', () {
159+
// The home filter drawer calls this directly (it used to exact-match,
160+
// so selecting "work" hid "work.sub" tasks the report engine showed).
161+
// Pin the seam itself, not just applyFilter above it.
162+
test('exact project matches', () {
163+
expect(VirtualFilterEngine.projectMatches('work', 'work'), isTrue);
164+
});
165+
test('child project matches its parent', () {
166+
expect(VirtualFilterEngine.projectMatches('work.sub', 'work'), isTrue);
167+
expect(
168+
VirtualFilterEngine.projectMatches('work.sub.deep', 'work'), isTrue);
169+
});
170+
test('a sibling sharing the prefix does not match', () {
171+
expect(VirtualFilterEngine.projectMatches('workshop', 'work'), isFalse);
172+
});
173+
test('parent does not match when a child is selected', () {
174+
expect(VirtualFilterEngine.projectMatches('work', 'work.sub'), isFalse);
175+
});
176+
test('no project never matches a selection', () {
177+
expect(VirtualFilterEngine.projectMatches(null, 'work'), isFalse);
178+
expect(VirtualFilterEngine.projectMatches('', 'work'), isFalse);
179+
});
180+
});
181+
158182
group('ReportService.execute', () {
159183
ReportDefinition report(String name) =>
160184
ReportService.defaultReports.firstWhere((r) => r.name == name);

0 commit comments

Comments
 (0)