mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 23:36:20 +00:00
feat(app): quick switcher also finds pages by block content
BlockHit carries the page id so a hit opens its page (journals included). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a6d566ff6f
commit
b44cbee038
9 files changed
+204
-30
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:synapse/src/state/app_state.dart';
|
||||
import 'package:synapse/src/theme/theme.dart';
|
||||
import 'package:synapse/src/views/quick_switcher.dart';
|
||||
|
||||
import 'support/memory_backend.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('the quick switcher finds pages by their content', (
|
||||
tester,
|
||||
) async {
|
||||
final b = MemoryBackend();
|
||||
final recipes = b.createPage('Recipes');
|
||||
b.seed(recipes.id, [(0, 'Tortilla de patatas con cebolla')]);
|
||||
final soups = b.createPage('Soups');
|
||||
b.seed(soups.id, [(0, 'Gazpacho'), (0, 'Salmorejo con cebolla')]);
|
||||
final cebolla = b.createPage('Cebolla');
|
||||
b.seed(cebolla.id, [(0, 'cebolla morada')]);
|
||||
final app = AppState(b);
|
||||
await tester.pumpWidget(
|
||||
AppScope(
|
||||
state: app,
|
||||
child: MaterialApp(
|
||||
theme: buildTheme(Brightness.light),
|
||||
home: const Scaffold(body: QuickSwitcher()),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.enterText(find.byType(TextField), 'cebolla');
|
||||
await tester.pumpAndSettle();
|
||||
// The title hit first, then one row per other page whose blocks match.
|
||||
expect(find.text('IN NOTES'), findsOneWidget);
|
||||
expect(find.text('Recipes'), findsOneWidget);
|
||||
expect(find.text('Soups'), findsOneWidget);
|
||||
expect(find.text('Cebolla'), findsOneWidget);
|
||||
await tester.tap(find.text('Soups'));
|
||||
await tester.pumpAndSettle();
|
||||
expect((app.route as PageTarget).id, soups.id);
|
||||
});
|
||||
}
|
||||
@@ -291,8 +291,21 @@ class MemoryBackend implements GraphBackend {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<BlockHit>> searchBlocks(String query, {int limit = 20}) async =>
|
||||
[];
|
||||
Future<List<BlockHit>> searchBlocks(String query, {int limit = 20}) async {
|
||||
final q = query.trim().toLowerCase();
|
||||
if (q.isEmpty) return [];
|
||||
return [
|
||||
for (final e in outlines.entries)
|
||||
for (final n in e.value)
|
||||
if (n.content.toLowerCase().contains(q))
|
||||
BlockHit(
|
||||
id: n.id,
|
||||
content: n.content,
|
||||
pageId: e.key,
|
||||
pageTitle: pages[e.key]?.title ?? '',
|
||||
),
|
||||
].take(limit).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
String? assetPath(String hash) => null;
|
||||
|
||||
Reference in new issue
Block a user