From 2e71cc573d1d890a7cd75ee9ef29429a75cc4409 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 3 Sep 2019 12:07:18 -0500 Subject: [PATCH] Cap the possible destination index used during Feed moves --- iOS/MasterFeed/MasterFeedViewController.swift | 2 +- iOS/SceneCoordinator.swift | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index a7eaa4146..6dc3d6e88 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -269,7 +269,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { if proposedDestinationIndexPath.section == 0 { return IndexPath(row: 0, section: 1) } - return proposedDestinationIndexPath + return coordinator.cappedIndexPath(proposedDestinationIndexPath) }() guard let draggedNode = coordinator.nodeFor(sourceIndexPath), let destNode = coordinator.nodeFor(destIndexPath), let parentNode = destNode.parent else { diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 544a848f6..f5f1924af 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -357,6 +357,13 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { return shadowTable[section] } + func cappedIndexPath(_ indexPath: IndexPath) -> IndexPath { + guard indexPath.section < shadowTable.count && indexPath.row < shadowTable[indexPath.section].count else { + return IndexPath(row: shadowTable[shadowTable.count - 1].count - 1, section: shadowTable.count - 1) + } + return indexPath + } + func indexPathFor(_ node: Node) -> IndexPath? { for i in 0..