From 6bf5f6efd46c47293fb54b9e9a25d91d8c6bec0d Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 7 Sep 2022 23:11:44 +0200 Subject: [PATCH] fix: dragging a list on mobile Safari --- src/components/home/navigation.vue | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/home/navigation.vue b/src/components/home/navigation.vue index 108d7fd71..33cbf62f8 100644 --- a/src/components/home/navigation.vue +++ b/src/components/home/navigation.vue @@ -250,9 +250,14 @@ async function saveListPosition(e: SortableEvent) { const newNamespaceIndex = parseInt(e.to.dataset.namespaceIndex as string) const listsActive = activeLists.value[newNamespaceIndex] - const list = listsActive[e.newIndex] - const listBefore = listsActive[e.newIndex - 1] ?? null - const listAfter = listsActive[e.newIndex + 1] ?? null + // If the list was dragged to the last position, Safari will report e.newIndex as the size of the listsActive + // array instead of using the position. Because the index is wrong in that case, dragging the list will fail. + // To work around that we're explicitly checking that case here and decrease the index. + const newIndex = e.newIndex === listsActive.length ? e.newIndex - 1 : e.newIndex + + const list = listsActive[newIndex] + const listBefore = listsActive[newIndex - 1] ?? null + const listAfter = listsActive[newIndex + 1] ?? null listUpdating.value[list.id] = true const position = calculateItemPosition(