mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
feat(app): new page and delete actions in All pages, tab tests and docs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e32cf0df3
commit
399c65ca6f
4 files changed
+750
-76
No files matched your search
@@ -5,6 +5,7 @@ import '../state/app_state.dart';
|
||||
import '../theme/theme.dart';
|
||||
import '../widgets/common.dart';
|
||||
import '../widgets/dates.dart';
|
||||
import '../widgets/pickers.dart' show errorText;
|
||||
|
||||
enum PageSort {
|
||||
edited('Edited'),
|
||||
@@ -28,6 +29,8 @@ class _AllPagesViewState extends State<AllPagesView> {
|
||||
final _pages = <PageDto>[];
|
||||
PageSort _sort = PageSort.edited;
|
||||
bool _ascending = false;
|
||||
bool _selecting = false;
|
||||
final _chosen = <String>{};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -77,6 +80,74 @@ class _AllPagesViewState extends State<AllPagesView> {
|
||||
app.reload();
|
||||
}
|
||||
|
||||
Future<void> _newPage() async {
|
||||
final app = AppScope.read(context);
|
||||
final id = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => NewPageDialog(app: app),
|
||||
);
|
||||
if (id == null) return;
|
||||
app.go(PageTarget(id: id));
|
||||
}
|
||||
|
||||
/// Asks for confirmation, then deletes `targets` and tidies tabs, recents and the list.
|
||||
Future<void> _delete(List<PageDto> targets) async {
|
||||
if (targets.isEmpty) return;
|
||||
final app = AppScope.read(context);
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => DeletePagesDialog(pages: targets),
|
||||
);
|
||||
if (ok != true) return;
|
||||
final ids = [for (final p in targets) p.id];
|
||||
try {
|
||||
for (final id in ids) {
|
||||
await app.queue.run(() => app.backend.deletePage(id));
|
||||
}
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
|
||||
app.reload();
|
||||
return;
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_pages.removeWhere((p) => ids.contains(p.id));
|
||||
_chosen.removeAll(ids);
|
||||
if (_chosen.isEmpty) _selecting = false;
|
||||
});
|
||||
}
|
||||
app.pagesDeleted(ids);
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Deleted ${ids.length} ${ids.length == 1 ? 'page' : 'pages'}',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _toggleSelect() => setState(() {
|
||||
_selecting = !_selecting;
|
||||
_chosen.clear();
|
||||
});
|
||||
|
||||
Future<void> _rowMenu(PageDto p, Offset at) async {
|
||||
final app = AppScope.read(context);
|
||||
final v = await showMenu<String>(
|
||||
context: context,
|
||||
position: RelativeRect.fromLTRB(at.dx, at.dy, at.dx, at.dy),
|
||||
items: _menuItems,
|
||||
);
|
||||
if (v == 'tab') app.openIdInNewTab(p.id);
|
||||
if (v == 'delete') await _delete([p]);
|
||||
}
|
||||
|
||||
static const _menuItems = [
|
||||
PopupMenuItem(value: 'tab', child: Text('Open in new tab')),
|
||||
PopupMenuItem(value: 'delete', child: Text('Delete…')),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final app = AppScope.read(context);
|
||||
@@ -93,57 +164,101 @@ class _AllPagesViewState extends State<AllPagesView> {
|
||||
itemCount: pages.length + 1,
|
||||
itemBuilder: (context, i) {
|
||||
if (i == 0) {
|
||||
final title = Text(
|
||||
'All pages',
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
);
|
||||
final actions = <Widget>[
|
||||
PopupMenuButton<PageSort>(
|
||||
key: const ValueKey('page-sort'),
|
||||
tooltip: 'Sort by',
|
||||
initialValue: _sort,
|
||||
onSelected: (v) => setState(() {
|
||||
_sort = v;
|
||||
_ascending = false;
|
||||
}),
|
||||
itemBuilder: (_) => [
|
||||
for (final v in PageSort.values)
|
||||
PopupMenuItem(value: v, child: Text(v.label)),
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Text(
|
||||
_sort.label,
|
||||
style: TextStyle(fontSize: 13, color: colors.muted),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
key: const ValueKey('page-sort-direction'),
|
||||
tooltip: _ascending ? 'Ascending' : 'Descending',
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: 18,
|
||||
color: colors.muted,
|
||||
icon: Icon(
|
||||
_ascending
|
||||
? Icons.arrow_upward_rounded
|
||||
: Icons.arrow_downward_rounded,
|
||||
),
|
||||
onPressed: () => setState(() => _ascending = !_ascending),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
TextLink(
|
||||
'Clean up',
|
||||
icon: Icons.cleaning_services_outlined,
|
||||
onTap: _cleanUp,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
TextLink(
|
||||
_selecting ? 'Done' : 'Select',
|
||||
key: const ValueKey('pages-select'),
|
||||
icon: _selecting
|
||||
? Icons.check_rounded
|
||||
: Icons.checklist_rounded,
|
||||
onTap: _toggleSelect,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
if (_selecting)
|
||||
FilledButton(
|
||||
key: const ValueKey('pages-delete-selected'),
|
||||
onPressed: _chosen.isEmpty
|
||||
? null
|
||||
: () => _delete([
|
||||
for (final p in _pages)
|
||||
if (_chosen.contains(p.id)) p,
|
||||
]),
|
||||
child: Text('Delete (${_chosen.length})'),
|
||||
)
|
||||
else
|
||||
FilledButton.icon(
|
||||
key: const ValueKey('new-page'),
|
||||
onPressed: _newPage,
|
||||
icon: const Icon(Icons.add_rounded, size: 18),
|
||||
label: const Text('New page'),
|
||||
),
|
||||
];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'All pages',
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
// Narrow widths: the actions wrap below the title.
|
||||
child: box.maxWidth < 760
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
title,
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
runSpacing: 6,
|
||||
children: actions,
|
||||
),
|
||||
],
|
||||
)
|
||||
: Row(
|
||||
children: [
|
||||
Expanded(child: title),
|
||||
...actions,
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuButton<PageSort>(
|
||||
key: const ValueKey('page-sort'),
|
||||
tooltip: 'Sort by',
|
||||
initialValue: _sort,
|
||||
onSelected: (v) => setState(() {
|
||||
_sort = v;
|
||||
_ascending = false;
|
||||
}),
|
||||
itemBuilder: (_) => [
|
||||
for (final v in PageSort.values)
|
||||
PopupMenuItem(value: v, child: Text(v.label)),
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Text(
|
||||
_sort.label,
|
||||
style: TextStyle(fontSize: 13, color: colors.muted),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
key: const ValueKey('page-sort-direction'),
|
||||
tooltip: _ascending ? 'Ascending' : 'Descending',
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: 18,
|
||||
color: colors.muted,
|
||||
icon: Icon(
|
||||
_ascending
|
||||
? Icons.arrow_upward_rounded
|
||||
: Icons.arrow_downward_rounded,
|
||||
),
|
||||
onPressed: () => setState(() => _ascending = !_ascending),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
TextLink(
|
||||
'Clean up',
|
||||
icon: Icons.cleaning_services_outlined,
|
||||
onTap: _cleanUp,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
final p = pages[i - 1];
|
||||
@@ -151,35 +266,85 @@ class _AllPagesViewState extends State<AllPagesView> {
|
||||
p.updatedAt.toInt(),
|
||||
);
|
||||
return InkWell(
|
||||
key: ValueKey('page-row-${p.id}'),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => app.openId(p.id),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
p.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 14.5, color: colors.ink),
|
||||
onTap: _selecting
|
||||
? () => setState(
|
||||
() => _chosen.contains(p.id)
|
||||
? _chosen.remove(p.id)
|
||||
: _chosen.add(p.id),
|
||||
)
|
||||
: () => app.navigate(PageTarget(id: p.id)),
|
||||
onSecondaryTapUp: _selecting
|
||||
? null
|
||||
: (d) => _rowMenu(p, d.globalPosition),
|
||||
child: GestureDetector(
|
||||
onTertiaryTapUp: _selecting
|
||||
? null
|
||||
: (_) => app.openIdInNewTab(p.id),
|
||||
onLongPressStart: _selecting
|
||||
? null
|
||||
: (d) => _rowMenu(p, d.globalPosition),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
if (_selecting)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 10),
|
||||
child: Icon(
|
||||
_chosen.contains(p.id)
|
||||
? Icons.check_box_rounded
|
||||
: Icons.check_box_outline_blank_rounded,
|
||||
key: ValueKey('page-check-${p.id}'),
|
||||
size: 20,
|
||||
color: _chosen.contains(p.id)
|
||||
? colors.accent
|
||||
: colors.faint,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
p.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 14.5, color: colors.ink),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (p.originJournal != null)
|
||||
Text(
|
||||
'born ${shortDate(parseDay(p.originJournal!))}',
|
||||
style: TextStyle(fontSize: 12, color: colors.faint),
|
||||
if (p.originJournal != null)
|
||||
Text(
|
||||
'born ${shortDate(parseDay(p.originJournal!))}',
|
||||
style: TextStyle(fontSize: 12, color: colors.faint),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
SizedBox(
|
||||
width: 70,
|
||||
child: Text(
|
||||
shortDate(edited),
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(fontSize: 12, color: colors.muted),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
SizedBox(
|
||||
width: 70,
|
||||
child: Text(
|
||||
shortDate(edited),
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(fontSize: 12, color: colors.muted),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (!_selecting)
|
||||
PopupMenuButton<String>(
|
||||
key: ValueKey('page-menu-${p.id}'),
|
||||
tooltip: 'More',
|
||||
iconSize: 18,
|
||||
padding: EdgeInsets.zero,
|
||||
icon: Icon(
|
||||
Icons.more_horiz_rounded,
|
||||
color: colors.faint,
|
||||
),
|
||||
itemBuilder: (_) => _menuItems,
|
||||
onSelected: (v) {
|
||||
if (v == 'tab') app.openIdInNewTab(p.id);
|
||||
if (v == 'delete') _delete([p]);
|
||||
},
|
||||
)
|
||||
else
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -273,3 +438,155 @@ class _CleanupDialogState extends State<CleanupDialog> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Asks for a page title. Pops with the id of the created page, or of the existing one when
|
||||
/// the user picks "Open it" after a duplicate-title error.
|
||||
class NewPageDialog extends StatefulWidget {
|
||||
const NewPageDialog({super.key, required this.app});
|
||||
final AppState app;
|
||||
|
||||
@override
|
||||
State<NewPageDialog> createState() => _NewPageDialogState();
|
||||
}
|
||||
|
||||
class _NewPageDialogState extends State<NewPageDialog> {
|
||||
final _text = TextEditingController();
|
||||
String? _error;
|
||||
String? _existingId;
|
||||
bool _busy = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_text.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _create() async {
|
||||
final title = _text.text.trim();
|
||||
if (title.isEmpty) {
|
||||
setState(() {
|
||||
_error = 'Enter a title';
|
||||
_existingId = null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (_busy) return;
|
||||
setState(() {
|
||||
_busy = true;
|
||||
_error = null;
|
||||
_existingId = null;
|
||||
});
|
||||
final app = widget.app;
|
||||
try {
|
||||
final existing = await app.backend.pageByTitle(title);
|
||||
if (existing != null) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_busy = false;
|
||||
_error = 'A page titled "${existing.page.title}" already exists';
|
||||
_existingId = existing.page.id;
|
||||
});
|
||||
return;
|
||||
}
|
||||
final page = await app.queue.run(() => app.backend.openPage(title));
|
||||
if (mounted) Navigator.pop(context, page.page.id);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_busy = false;
|
||||
_error = errorText(e);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AlertDialog(
|
||||
title: const Text('New page'),
|
||||
content: SizedBox(
|
||||
width: 380,
|
||||
child: TextField(
|
||||
key: const ValueKey('new-page-title'),
|
||||
controller: _text,
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(hintText: 'Title', errorText: _error),
|
||||
onChanged: (_) {
|
||||
if (_error != null) {
|
||||
setState(() {
|
||||
_error = null;
|
||||
_existingId = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
onSubmitted: (_) => _create(),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
if (_existingId != null)
|
||||
TextButton(
|
||||
key: const ValueKey('open-existing'),
|
||||
onPressed: () => Navigator.pop(context, _existingId),
|
||||
child: const Text('Open it'),
|
||||
),
|
||||
FilledButton(
|
||||
key: const ValueKey('create-page'),
|
||||
onPressed: _create,
|
||||
child: const Text('Create'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Confirmation before deleting pages; pops true when confirmed.
|
||||
class DeletePagesDialog extends StatelessWidget {
|
||||
const DeletePagesDialog({super.key, required this.pages});
|
||||
final List<PageDto> pages;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final n = pages.length;
|
||||
final hubs = pages.any((p) => p.isHub);
|
||||
final journals = pages.any((p) => p.journalDate != null);
|
||||
return AlertDialog(
|
||||
title: Text('Delete $n ${n == 1 ? 'page' : 'pages'}?'),
|
||||
content: SizedBox(
|
||||
width: 420,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Their blocks are removed; links to them stay as plain references.',
|
||||
),
|
||||
if (hubs) ...[
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
"Hubs: their members leave the hub, and the hub's template "
|
||||
'is deleted with it.',
|
||||
),
|
||||
],
|
||||
if (journals) ...[
|
||||
const SizedBox(height: 8),
|
||||
const Text('This includes journal pages.'),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
key: const ValueKey('confirm-delete'),
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text('Delete'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ class _TopBar extends StatelessWidget {
|
||||
const Spacer(),
|
||||
if (narrow) const TabCountButton(),
|
||||
// Phones: an icon instead of the pill keeps the bar from overflowing.
|
||||
if (MediaQuery.sizeOf(context).width < 480)
|
||||
if (MediaQuery.sizeOf(context).width < 600)
|
||||
icon(
|
||||
Icons.search_rounded,
|
||||
'Search (${app.keymap.of(AppAction.quickSwitcher).label})',
|
||||
|
||||
@@ -0,0 +1,339 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:synapse/src/backend/graph_backend.dart';
|
||||
import 'package:synapse/src/state/app_state.dart';
|
||||
import 'package:synapse/src/state/settings.dart';
|
||||
import 'package:synapse/src/theme/theme.dart';
|
||||
import 'package:synapse/src/views/all_pages_view.dart';
|
||||
import 'package:synapse/src/views/shell.dart';
|
||||
|
||||
import 'support/memory_backend.dart';
|
||||
|
||||
MemoryBackend demo() {
|
||||
final b = MemoryBackend();
|
||||
for (final t in ['Alpha', 'Beta', 'Gamma']) {
|
||||
b.createPage(t);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
PageDto byTitle(MemoryBackend b, String t) =>
|
||||
b.pages.values.firstWhere((p) => p.title == t);
|
||||
|
||||
Future<void> settle(WidgetTester tester) async {
|
||||
for (var i = 0; i < 6; i++) {
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
}
|
||||
}
|
||||
|
||||
Future<AppState> pump(
|
||||
WidgetTester tester,
|
||||
MemoryBackend b, {
|
||||
Widget home = const Shell(),
|
||||
AppState? state,
|
||||
Size size = const Size(1600, 1000),
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final app = state ?? AppState(b);
|
||||
await tester.pumpWidget(
|
||||
AppScope(
|
||||
state: app,
|
||||
child: MaterialApp(theme: buildTheme(Brightness.light), home: home),
|
||||
),
|
||||
);
|
||||
await settle(tester);
|
||||
return app;
|
||||
}
|
||||
|
||||
Future<void> chord(
|
||||
WidgetTester tester,
|
||||
LogicalKeyboardKey key, {
|
||||
bool shift = false,
|
||||
}) async {
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
if (shift) await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
|
||||
await tester.sendKeyEvent(key);
|
||||
if (shift) await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await settle(tester);
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('tab state', () {
|
||||
test('each tab keeps its own history', () {
|
||||
final app = AppState(demo());
|
||||
app.go(const AllPagesRoute());
|
||||
app.openInNewTab(const SettingsRoute());
|
||||
expect(app.tabs.length, 2);
|
||||
expect(app.activeTab, 1);
|
||||
expect(app.canGoBack, isFalse);
|
||||
app.go(const TimelineRoute());
|
||||
expect(app.canGoBack, isTrue);
|
||||
app.activateTab(0);
|
||||
expect(app.route, isA<AllPagesRoute>());
|
||||
app.back();
|
||||
expect(app.route, isA<JournalsRoute>());
|
||||
app.activateTab(1);
|
||||
expect(app.route, isA<TimelineRoute>());
|
||||
app.back();
|
||||
expect(app.route, isA<SettingsRoute>());
|
||||
app.forward();
|
||||
expect(app.route, isA<TimelineRoute>());
|
||||
});
|
||||
|
||||
test(
|
||||
'closing tabs keeps the active one sensible; the last leaves Journals',
|
||||
() {
|
||||
final app = AppState(demo());
|
||||
app.openInNewTab(const AllPagesRoute());
|
||||
app.openInNewTab(const SettingsRoute(), activate: false);
|
||||
expect(app.activeTab, 1);
|
||||
app.closeTab(0);
|
||||
expect(app.activeTab, 0);
|
||||
expect(app.route, isA<AllPagesRoute>());
|
||||
app.closeTab();
|
||||
expect(app.route, isA<SettingsRoute>());
|
||||
app.closeTab();
|
||||
expect(app.tabs.length, 1);
|
||||
expect(app.route, isA<JournalsRoute>());
|
||||
},
|
||||
);
|
||||
|
||||
test('tabs persist across a restart; broken entries are skipped', () {
|
||||
final store = MemorySettings();
|
||||
final b = demo();
|
||||
final alpha = byTitle(b, 'Alpha');
|
||||
final app = AppState(b, settings: store);
|
||||
app.go(PageTarget(id: alpha.id));
|
||||
app.openInNewTab(const GraphRoute(GraphMode.tree, focusId: 'x'));
|
||||
app.openInNewTab(const AllPagesRoute());
|
||||
app.activateTab(1);
|
||||
final saved = store.load();
|
||||
(saved['tabs']['items'] as List).insert(1, {'t': 'nonsense'});
|
||||
(saved['tabs']['items'] as List).add('garbage');
|
||||
saved['tabs']['active'] = 2;
|
||||
store.save(saved);
|
||||
|
||||
final again = AppState(b, settings: store);
|
||||
expect(again.tabs.length, 3);
|
||||
expect(again.activeTab, 2);
|
||||
expect((again.tabs[0].route as PageTarget).id, alpha.id);
|
||||
final g = again.tabs[1].route as GraphRoute;
|
||||
expect(g.mode, GraphMode.tree);
|
||||
expect(g.focusId, 'x');
|
||||
expect(again.tabs[2].route, isA<AllPagesRoute>());
|
||||
expect(again.canGoBack, isFalse);
|
||||
});
|
||||
|
||||
test('deleting a page falls back in tabs and drops recents', () {
|
||||
final b = demo();
|
||||
final alpha = byTitle(b, 'Alpha');
|
||||
final beta = byTitle(b, 'Beta');
|
||||
final app = AppState(b);
|
||||
app.go(PageTarget(id: beta.id));
|
||||
app.go(PageTarget(id: alpha.id));
|
||||
app.openInNewTab(PageTarget(id: alpha.id));
|
||||
app.recent.add(
|
||||
PageBrief(id: alpha.id, title: 'Alpha', isJournal: false, isHub: false),
|
||||
);
|
||||
app.pagesDeleted([alpha.id]);
|
||||
expect(app.recent, isEmpty);
|
||||
expect(app.route, isA<JournalsRoute>());
|
||||
app.activateTab(0);
|
||||
expect((app.route as PageTarget).id, beta.id);
|
||||
});
|
||||
});
|
||||
|
||||
group('tabs UI', () {
|
||||
testWidgets('keyboard shortcuts open, switch and close tabs', (
|
||||
tester,
|
||||
) async {
|
||||
final app = await pump(tester, demo());
|
||||
expect(app.tabs.length, 1);
|
||||
await chord(tester, LogicalKeyboardKey.keyT);
|
||||
expect(app.tabs.length, 2);
|
||||
expect(app.activeTab, 1);
|
||||
await chord(tester, LogicalKeyboardKey.tab);
|
||||
expect(app.activeTab, 0);
|
||||
await chord(tester, LogicalKeyboardKey.tab, shift: true);
|
||||
expect(app.activeTab, 1);
|
||||
await chord(tester, LogicalKeyboardKey.keyW);
|
||||
expect(app.tabs.length, 1);
|
||||
await chord(tester, LogicalKeyboardKey.keyW);
|
||||
expect(app.tabs.length, 1);
|
||||
expect(app.route, isA<JournalsRoute>());
|
||||
});
|
||||
|
||||
testWidgets('strip shows titles; middle-click closes, plus opens', (
|
||||
tester,
|
||||
) async {
|
||||
final app = await pump(tester, demo());
|
||||
app.go(const AllPagesRoute());
|
||||
await settle(tester);
|
||||
await tester.tap(find.byKey(const ValueKey('tab-new')));
|
||||
await settle(tester);
|
||||
expect(app.tabs.length, 2);
|
||||
final strip = find.byKey(const ValueKey('tab-strip'));
|
||||
expect(
|
||||
find.descendant(of: strip, matching: find.text('All pages')),
|
||||
findsOneWidget,
|
||||
);
|
||||
final at = tester.getCenter(
|
||||
find.descendant(of: strip, matching: find.text('All pages')),
|
||||
);
|
||||
final mouse = await tester.createGesture(
|
||||
kind: PointerDeviceKind.mouse,
|
||||
buttons: kMiddleMouseButton,
|
||||
);
|
||||
await mouse.down(at);
|
||||
await mouse.up();
|
||||
await settle(tester);
|
||||
expect(app.tabs.length, 1);
|
||||
expect(app.route, isA<JournalsRoute>());
|
||||
});
|
||||
|
||||
testWidgets('narrow layout lists tabs in a sheet', (tester) async {
|
||||
final app = await pump(tester, demo(), size: const Size(500, 900));
|
||||
app.openInNewTab(const AllPagesRoute());
|
||||
await settle(tester);
|
||||
expect(find.byKey(const ValueKey('tab-strip')), findsNothing);
|
||||
await tester.tap(find.byKey(const ValueKey('tab-count')));
|
||||
await settle(tester);
|
||||
expect(find.byKey(const ValueKey('sheet-tab-1')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const ValueKey('sheet-tab-0')));
|
||||
await settle(tester);
|
||||
expect(app.activeTab, 0);
|
||||
await tester.tap(find.byKey(const ValueKey('tab-count')));
|
||||
await settle(tester);
|
||||
await tester.tap(find.byKey(const ValueKey('sheet-tab-close-1')));
|
||||
await settle(tester);
|
||||
expect(app.tabs.length, 1);
|
||||
});
|
||||
|
||||
testWidgets('ctrl+click on an All pages row opens a new tab', (
|
||||
tester,
|
||||
) async {
|
||||
final b = demo();
|
||||
final app = await pump(tester, b, state: AppState(b));
|
||||
app.go(const AllPagesRoute());
|
||||
await settle(tester);
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.tap(find.text('Beta'));
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await settle(tester);
|
||||
expect(app.tabs.length, 2);
|
||||
expect(app.activeTab, 1);
|
||||
expect((app.route as PageTarget).id, byTitle(b, 'Beta').id);
|
||||
expect(app.tabs[0].route, isA<AllPagesRoute>());
|
||||
});
|
||||
});
|
||||
|
||||
group('All pages actions', () {
|
||||
testWidgets('new page: validation, duplicate error and open it', (
|
||||
tester,
|
||||
) async {
|
||||
final b = demo();
|
||||
final app = await pump(
|
||||
tester,
|
||||
b,
|
||||
home: const Scaffold(body: AllPagesView()),
|
||||
);
|
||||
await tester.tap(find.byKey(const ValueKey('new-page')));
|
||||
await settle(tester);
|
||||
await tester.tap(find.byKey(const ValueKey('create-page')));
|
||||
await settle(tester);
|
||||
expect(find.text('Enter a title'), findsOneWidget);
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(const ValueKey('new-page-title')),
|
||||
'alpha',
|
||||
);
|
||||
await tester.tap(find.byKey(const ValueKey('create-page')));
|
||||
await settle(tester);
|
||||
expect(find.textContaining('already exists'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const ValueKey('open-existing')));
|
||||
await settle(tester);
|
||||
expect((app.route as PageTarget).id, byTitle(b, 'Alpha').id);
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('new-page')));
|
||||
await settle(tester);
|
||||
await tester.enterText(
|
||||
find.byKey(const ValueKey('new-page-title')),
|
||||
'Delta',
|
||||
);
|
||||
await tester.tap(find.byKey(const ValueKey('create-page')));
|
||||
await settle(tester);
|
||||
expect(b.pages.values.where((p) => p.title == 'Delta').length, 1);
|
||||
expect((app.route as PageTarget).id, byTitle(b, 'Delta').id);
|
||||
});
|
||||
|
||||
testWidgets('single delete asks first and says what happens', (
|
||||
tester,
|
||||
) async {
|
||||
final b = demo();
|
||||
final beta = byTitle(b, 'Beta');
|
||||
await pump(tester, b, home: const Scaffold(body: AllPagesView()));
|
||||
await tester.tap(find.byKey(ValueKey('page-menu-${beta.id}')));
|
||||
await settle(tester);
|
||||
await tester.tap(find.text('Delete…'));
|
||||
await settle(tester);
|
||||
expect(find.text('Delete 1 page?'), findsOneWidget);
|
||||
expect(find.textContaining('plain references'), findsOneWidget);
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await settle(tester);
|
||||
expect(b.pages.containsKey(beta.id), isTrue);
|
||||
|
||||
await tester.tap(find.byKey(ValueKey('page-menu-${beta.id}')));
|
||||
await settle(tester);
|
||||
await tester.tap(find.text('Delete…'));
|
||||
await settle(tester);
|
||||
await tester.tap(find.byKey(const ValueKey('confirm-delete')));
|
||||
await settle(tester);
|
||||
expect(b.pages.containsKey(beta.id), isFalse);
|
||||
expect(find.text('Beta'), findsNothing);
|
||||
expect(find.text('Deleted 1 page'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('bulk delete in selection mode; open tab falls back', (
|
||||
tester,
|
||||
) async {
|
||||
final b = demo();
|
||||
final alpha = byTitle(b, 'Alpha');
|
||||
final beta = byTitle(b, 'Beta');
|
||||
final app = await pump(tester, b, home: const Shell());
|
||||
app.go(PageTarget(id: alpha.id));
|
||||
app.openInNewTab(const AllPagesRoute());
|
||||
await settle(tester);
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('pages-select')));
|
||||
await settle(tester);
|
||||
expect(
|
||||
tester
|
||||
.widget<FilledButton>(
|
||||
find.byKey(const ValueKey('pages-delete-selected')),
|
||||
)
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
await tester.tap(find.byKey(ValueKey('page-row-${alpha.id}')));
|
||||
await tester.tap(find.byKey(ValueKey('page-row-${beta.id}')));
|
||||
await settle(tester);
|
||||
await tester.tap(find.byKey(const ValueKey('pages-delete-selected')));
|
||||
await settle(tester);
|
||||
expect(find.text('Delete 2 pages?'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const ValueKey('confirm-delete')));
|
||||
await settle(tester);
|
||||
|
||||
expect(b.pages.values.map((p) => p.title), isNot(contains('Alpha')));
|
||||
expect(b.pages.values.map((p) => p.title), isNot(contains('Beta')));
|
||||
expect(find.text('Deleted 2 pages'), findsOneWidget);
|
||||
app.activateTab(0);
|
||||
await settle(tester);
|
||||
expect(app.route, isA<JournalsRoute>());
|
||||
});
|
||||
});
|
||||
}
|
||||
+19
-1
@@ -79,7 +79,21 @@ Commit the regenerated `crates/synapse-ffi/src/frb_generated.rs` and `app/lib/sr
|
||||
structure wins if they ever disagree.
|
||||
- App shortcuts (defaults, all rebindable in Settings): Ctrl+K quick switcher, Ctrl+Shift+J
|
||||
journals, Ctrl+Shift+G graph, Ctrl+Shift+T timeline, Ctrl+\ sidebar, Ctrl+Shift+\ graph
|
||||
sidebar, Ctrl+, settings, Alt+←/→ back/forward.
|
||||
sidebar, Ctrl+, settings, Alt+←/→ back/forward, Ctrl+T new tab, Ctrl+W close tab,
|
||||
Ctrl+Tab / Ctrl+Shift+Tab next/previous tab.
|
||||
|
||||
## Tabs
|
||||
- `AppState` holds a list of `AppTab`s; each has its own route and back/forward history, and
|
||||
`go`/`back`/`forward`/`canGoBack` act on the active one. The strip (`views/tab_strip.dart`)
|
||||
sits under the top bar: × on hover or on the active tab, middle-click closes, drag reorders,
|
||||
"+" opens a Journals tab; closing the last tab leaves one Journals tab. Below 760 px the strip
|
||||
is replaced by a tab-count button in the top bar that opens a bottom sheet.
|
||||
- Ctrl/Cmd+click (or middle-click) on a page link or block ref in the editor, on sidebar
|
||||
entries, All pages rows and quick switcher results opens in a new tab
|
||||
(`AppState.navigate` / `openInNewTab`).
|
||||
- Open tabs (route type and page id/title, graph mode) and the active index are saved under
|
||||
`tabs` in the settings JSON and restored on start; history is not persisted. Deleting a page
|
||||
(`AppState.pagesDeleted`) sends tabs showing it back (or to Journals) and drops it from recents.
|
||||
|
||||
## Settings, themes and key bindings
|
||||
- Top-bar gear icon, next to the theme toggle (Ctrl+,): theme cards and the shortcut list. Click a shortcut, press the new
|
||||
@@ -156,6 +170,10 @@ comments, selectors and unknown properties are ignored (unknown `--vars` are rep
|
||||
related pages; on narrow windows they appear below the content.
|
||||
- All pages lists notes only (hubs are folders, not pages) and can be sorted by edited,
|
||||
created or title, ascending or descending.
|
||||
- "New page" asks for a title (empty or duplicate titles are refused inline, with "Open it"
|
||||
for an existing page). Each row has a `⋯` menu (also on right-click or long-press) with
|
||||
"Open in new tab" and "Delete…"; "Select" switches to checkboxes with a bulk "Delete (N)".
|
||||
Deletion always asks for confirmation and runs `deletePage` per page.
|
||||
|
||||
## Graph view
|
||||
One view (sidebar "Graph", Ctrl+Shift+G) with a mode selector:
|
||||
|
||||
Reference in new issue
Block a user