From e1718b7ec258b4a400e3f982a045b7776a523efd Mon Sep 17 00:00:00 2001 From: Fabian Freund Date: Mon, 9 Mar 2026 18:24:01 +0100 Subject: [PATCH] reordering hardening --- .../widgets/empty_state/top_sites_section.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/lib/features/geckoview/features/search/presentation/widgets/empty_state/top_sites_section.dart b/app/lib/features/geckoview/features/search/presentation/widgets/empty_state/top_sites_section.dart index 33329a46..c38075d3 100644 --- a/app/lib/features/geckoview/features/search/presentation/widgets/empty_state/top_sites_section.dart +++ b/app/lib/features/geckoview/features/search/presentation/widgets/empty_state/top_sites_section.dart @@ -239,9 +239,18 @@ class _ReorderableTopSitesGrid extends HookConsumerWidget { } else if (targetIndex >= items.length - 1) { key = await repo.getTrailingOrderKey(); } else if (targetIndex < oldIndex) { - key = (await repo.getOrderKeyAfterSite( - items[targetIndex - 1].id!, - ))!; + final previousId = items[targetIndex - 1].id; + final nextId = items[targetIndex + 1].id; + final afterPrevious = previousId == null + ? null + : await repo.getOrderKeyAfterSite(previousId); + if (afterPrevious != null) { + key = afterPrevious; + } else if (nextId != null) { + key = await repo.getOrderKeyBeforeSite(nextId); + } else { + key = await repo.getTrailingOrderKey(); + } } else { key = await repo.getOrderKeyBeforeSite( items[targetIndex + 1].id!,