mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-27 07:46:25 +00:00
fix(app): leave tabs that open a deleted page by title, so it is not recreated
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3d754a83e6
commit
a6d566ff6f
4 files changed
+22
-4
No files matched your search
@@ -485,9 +485,18 @@ class AppState extends ChangeNotifier {
|
|||||||
|
|
||||||
/// Pages were deleted: tabs showing them step back to the last surviving entry (or
|
/// Pages were deleted: tabs showing them step back to the last surviving entry (or
|
||||||
/// Journals) and the recents drop them.
|
/// Journals) and the recents drop them.
|
||||||
void pagesDeleted(Iterable<String> ids) {
|
///
|
||||||
|
/// Routes that open a page by title count too: left open, they would recreate it.
|
||||||
|
void pagesDeleted(
|
||||||
|
Iterable<String> ids, {
|
||||||
|
Iterable<String> titles = const [],
|
||||||
|
}) {
|
||||||
final gone = ids.toSet();
|
final gone = ids.toSet();
|
||||||
bool dead(AppRoute r) => r is PageTarget && gone.contains(r.id);
|
final goneTitles = {for (final t in titles) t.toLowerCase()};
|
||||||
|
bool dead(AppRoute r) =>
|
||||||
|
r is PageTarget &&
|
||||||
|
(gone.contains(r.id) ||
|
||||||
|
(r.title != null && goneTitles.contains(r.title!.toLowerCase())));
|
||||||
recent.removeWhere((p) => gone.contains(p.id));
|
recent.removeWhere((p) => gone.contains(p.id));
|
||||||
for (final t in _tabs) {
|
for (final t in _tabs) {
|
||||||
t.back.removeWhere(dead);
|
t.back.removeWhere(dead);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class _AllPagesViewState extends State<AllPagesView> {
|
|||||||
if (_chosen.isEmpty) _selecting = false;
|
if (_chosen.isEmpty) _selecting = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
app.pagesDeleted(ids);
|
app.pagesDeleted(ids, titles: [for (final p in targets) p.title]);
|
||||||
messenger.showSnackBar(
|
messenger.showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
|
|||||||
@@ -741,7 +741,7 @@ class PageMenu extends StatelessWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Tabs showing the page step back (or fall back to Journals); recents drop it.
|
// Tabs showing the page step back (or fall back to Journals); recents drop it.
|
||||||
app.pagesDeleted([page.id]);
|
app.pagesDeleted([page.id], titles: [page.title]);
|
||||||
messenger.showSnackBar(SnackBar(content: Text('Deleted "${page.title}"')));
|
messenger.showSnackBar(SnackBar(content: Text('Deleted "${page.title}"')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,15 @@ void main() {
|
|||||||
app.activateTab(0);
|
app.activateTab(0);
|
||||||
expect((app.route as PageTarget).id, beta.id);
|
expect((app.route as PageTarget).id, beta.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a page opened by title is left too, so it is not recreated', () {
|
||||||
|
final b = demo();
|
||||||
|
final alpha = byTitle(b, 'Alpha');
|
||||||
|
final app = AppState(b);
|
||||||
|
app.go(const PageTarget(title: 'alpha'));
|
||||||
|
app.pagesDeleted([alpha.id], titles: ['Alpha']);
|
||||||
|
expect(app.route, isA<JournalsRoute>());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('tabs UI', () {
|
group('tabs UI', () {
|
||||||
|
|||||||
Reference in new issue
Block a user