Skip to content

Commit

Permalink
Fix crash in targetIndexPathForMoveFromRowAt
Browse files Browse the repository at this point in the history
  • Loading branch information
PARAIPAN9 committed Feb 7, 2024
1 parent ccbbaf0 commit edc5a86
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,26 +445,17 @@ class SearchSettingsTableViewController: ThemedTableViewController, FeatureFlagg
targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath,
toProposedIndexPath proposedDestinationIndexPath: IndexPath
) -> IndexPath {
// You can't drag or drop on the default engine.
if sourceIndexPath.section == Section.defaultEngine.rawValue
|| proposedDestinationIndexPath.section == Section.defaultEngine.rawValue {
// Make drag or drop available only for quickEngines section
guard proposedDestinationIndexPath.section == Section.quickEngines.rawValue else {
return sourceIndexPath
}

// Can't drag/drop over "Add Custom Engine button"
let sourceIndexCheck = sourceIndexPath.item + 1 == model.orderedEngines.count
let destinationIndexCheck = proposedDestinationIndexPath.item + 1 == model.orderedEngines.count
if sourceIndexCheck || destinationIndexCheck {
// Can't drag/drop over "Add Search Engine button"
if [sourceIndexPath.item, proposedDestinationIndexPath.item]
.contains(where: { $0 + 1 == model.orderedEngines.count }) {
return sourceIndexPath
}

if sourceIndexPath.section != proposedDestinationIndexPath.section {
var row = 0
if sourceIndexPath.section < proposedDestinationIndexPath.section {
row = tableView.numberOfRows(inSection: sourceIndexPath.section) - 1
}
return IndexPath(row: row, section: sourceIndexPath.section)
}
return proposedDestinationIndexPath
}

Expand Down

0 comments on commit edc5a86

Please sign in to comment.