Skip to content

Commit

Permalink
Merge pull request #174 from kettch/moveToEnd-Beginning
Browse files Browse the repository at this point in the history
Move to beginning / end
  • Loading branch information
jwilling committed Jun 7, 2016
2 parents 78ebe6b + 11d8a6f commit e0e8634
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion JNWCollectionView/JNWCollectionViewFramework.m
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,27 @@ - (NSArray *)allIndexPaths {
return indexPaths.copy;
}

- (NSIndexPath *)firstIndexPath {
if ([self numberOfItemsInSection:0] > 0) {
return [NSIndexPath jnw_indexPathForItem:0 inSection:0];
}

return nil;
}

- (NSIndexPath *)lastIndexPath {
NSIndexPath *indexPath = nil;
NSInteger numberOfSections = self.data.numberOfSections;
if (numberOfSections > 0) {
JNWCollectionViewSection section = self.data.sections[numberOfSections - 1];
NSInteger numberOfItems = section.numberOfItems;
if (numberOfItems > 0) {
indexPath = [NSIndexPath jnw_indexPathForItem:numberOfItems - 1 inSection:numberOfSections - 1];
}
}
return indexPath;
}

- (NSArray *)indexPathsForItemsInRect:(CGRect)rect {
if (CGRectEqualToRect(rect, CGRectZero))
return [NSArray array];
Expand Down Expand Up @@ -1056,7 +1077,8 @@ - (void)rightClickInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(

- (void)moveUp:(id)sender {
NSIndexPath *toSelect = [self.collectionViewLayout indexPathForNextItemInDirection:JNWCollectionViewDirectionUp currentIndexPath:[self indexPathForSelectedItem]];
[self selectItemAtIndexPath:toSelect atScrollPosition:JNWCollectionViewScrollPositionNearest animated:YES];}
[self selectItemAtIndexPath:toSelect atScrollPosition:JNWCollectionViewScrollPositionNearest animated:YES];
}

- (void)moveUpAndModifySelection:(id)sender {
NSIndexPath *toSelect = [self.collectionViewLayout indexPathForNextItemInDirection:JNWCollectionViewDirectionUp currentIndexPath:[self indexPathForSelectedItem]];
Expand Down Expand Up @@ -1093,6 +1115,16 @@ - (void)moveLeftAndModifySelection:(id)sender {
[self selectItemAtIndexPath:toSelect atScrollPosition:JNWCollectionViewScrollPositionNearest animated:YES selectionType:JNWCollectionViewSelectionTypeExtending];
}

- (void)moveToBeginningOfDocument:(id)sender {
NSIndexPath *toSelect = [self firstIndexPath];
[self selectItemAtIndexPath:toSelect atScrollPosition:JNWCollectionViewScrollPositionNearest animated:YES];
}

- (void)moveToEndOfDocument:(id)sender {
NSIndexPath *toSelect = [self lastIndexPath];
[self selectItemAtIndexPath:toSelect atScrollPosition:JNWCollectionViewScrollPositionNearest animated:YES];
}

- (void)selectAll:(id)sender {
[self selectItemsAtIndexPaths:[self allIndexPaths] animated:YES];
}
Expand Down

0 comments on commit e0e8634

Please sign in to comment.