Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes keyboard navigation and live resize issues in BCCollectionView

  • Loading branch information...
commit cd436018bee2307906d48498c8749030c6b1007b 1 parent 5b9c8e9
@pieteromvlee pieteromvlee authored
View
4 BCCollectionView+Keyboard.h
@@ -18,3 +18,7 @@
- (void)moveDown:(id)sender;
- (void)moveDownAndModifySelection:(id)sender;
@end
+
+@interface NSIndexSet (BCCollectionView_IndexSet)
+- (NSIndexSet *)indexSetByRemovingIndex:(NSUInteger)index;
+@end
View
15 BCCollectionView+Keyboard.m
@@ -58,7 +58,7 @@ - (void)simpleExtendSelectionRange:(NSRange)range newIndex:(NSUInteger)newIndex
{
if (newIndex != NSNotFound) {
if ([selectionIndexes containsIndex:newIndex])
- [self deselectItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:range]];
+ [self deselectItemsAtIndexes:[[NSIndexSet indexSetWithIndexesInRange:range] indexSetByRemovingIndex:newIndex]];
else
[self selectItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:range]];
lastSelectionIndex = newIndex;
@@ -78,7 +78,7 @@ - (void)moveLeftAndModifySelection:(id)sender
{
NSPoint position = [layoutManager rowAndColumnPositionOfItemAtIndex:lastSelectionIndex];
NSUInteger newIndex = [layoutManager indexOfItemAtRow:position.y column:position.x-1];
- [self simpleExtendSelectionRange:NSMakeRange(newIndex, lastSelectionIndex-newIndex) newIndex:newIndex];
+ [self simpleExtendSelectionRange:NSMakeRange(newIndex, 2) newIndex:newIndex];
}
- (void)moveRight:(id)sender
@@ -91,7 +91,7 @@ - (void)moveRightAndModifySelection:(id)sender
{
NSPoint position = [layoutManager rowAndColumnPositionOfItemAtIndex:lastSelectionIndex];
NSUInteger newIndex = [layoutManager indexOfItemAtRow:position.y column:position.x+1];
- [self simpleExtendSelectionRange:NSMakeRange(lastSelectionIndex, newIndex-lastSelectionIndex+1) newIndex:newIndex];
+ [self simpleExtendSelectionRange:NSMakeRange(lastSelectionIndex, 2) newIndex:newIndex];
}
- (void)moveUp:(id)sender
@@ -148,3 +148,12 @@ - (void)deleteForward:(id)sender
}
@end
+
+@implementation NSIndexSet (BCCollectionView_IndexSet)
+- (NSIndexSet *)indexSetByRemovingIndex:(NSUInteger)index
+{
+ return [self indexesPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
+ return index != idx;
+ }];
+}
+@end
View
9 BCCollectionView.m
@@ -271,9 +271,7 @@ - (void)removeViewControllerForItemAtIndex:(NSUInteger)anIndex
{
NSNumber *key = [NSNumber numberWithInteger:anIndex];
NSViewController *viewController = [visibleViewControllers objectForKey:key];
- dispatch_async(dispatch_get_main_queue(), ^{
- [[viewController view] removeFromSuperview];
- });
+ [[viewController view] removeFromSuperview];
[self delegateUpdateDeselectionForItemAtIndex:anIndex];
[self delegateViewControllerBecameInvisibleAtIndex:anIndex];
@@ -553,11 +551,12 @@ - (void)viewDidResize
BOOL shouldBeVisible = NSIntersectsRect([layoutItem itemRect], visibleRect);
if (shouldBeVisible) {
NSViewController *controller = [self viewControllerForItemAtIndex:[layoutItem itemIndex]];
+// if (controller && ![[controller view] superview])
+// NSLog(@"nooooo");
if (controller)
[[controller view] setFrame:[layoutItem itemRect]];
- else {
+ else
[self addMissingViewControllerForItemAtIndex:[layoutItem itemIndex] withFrame:[layoutItem itemRect]];
- }
} else {
if ([self viewControllerForItemAtIndex:[layoutItem itemIndex]])
[self removeViewControllerForItemAtIndex:[layoutItem itemIndex]];
Please sign in to comment.
Something went wrong with that request. Please try again.