diff --git a/PBCommitList.h b/PBCommitList.h index 069aeae..d83dd80 100644 --- a/PBCommitList.h +++ b/PBCommitList.h @@ -16,9 +16,10 @@ IBOutlet WebView* webView; IBOutlet PBWebHistoryController *webController; IBOutlet PBGitHistoryController *controller; - + BOOL useAdjustScroll; NSPoint mouseDownPoint; } @property (readonly) NSPoint mouseDownPoint; +@property (assign) BOOL useAdjustScroll; @end diff --git a/PBCommitList.m b/PBCommitList.m index e2f6f23..0060a07 100644 --- a/PBCommitList.m +++ b/PBCommitList.m @@ -13,6 +13,8 @@ @implementation PBCommitList @synthesize mouseDownPoint; +@synthesize useAdjustScroll; + - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL) local { return NSDragOperationCopy; @@ -47,7 +49,39 @@ - (void) copy:(id)sender { [controller copyCommitInfo]; -}; +} + +// !!! Andre Berg 20100330: Used from -scrollSelectionToTopOfViewFrom: of PBGitHistoryController +// so that when the history controller udpates the branch filter the origin of the superview gets +// shifted into multiples of the row height. Otherwise the top selected row will always be off by +// a little bit depending on how much the bottom half of the split view is dragged down. +- (NSRect)adjustScroll:(NSRect)proposedVisibleRect { + + //NSLog(@"[%@ %s]: proposedVisibleRect: %@", [self class], _cmd, NSStringFromRect(proposedVisibleRect)); + NSRect newRect = proposedVisibleRect; + + // !!! Andre Berg 20100330: only modify if -scrollSelectionToTopOfViewFrom: has set useAdjustScroll to YES + // Otherwise we'd also constrain things like middle mouse scrolling. + if (useAdjustScroll) { + NSInteger rh = [self rowHeight]; + NSInteger ny = (NSInteger)proposedVisibleRect.origin.y % (NSInteger)rh; + NSInteger adj = rh - ny; + // check the targeted row and see if we need to add or subtract the difference (if there is one)... + NSRect sr = [self rectOfRow:[self selectedRow]]; + // NSLog(@"[%@ %s]: selectedRow %d, rect: %@", [self class], _cmd, [self selectedRow], NSStringFromRect(sr)); + if (sr.origin.y > proposedVisibleRect.origin.y) { + // NSLog(@"[%@ %s] selectedRow.origin.y > proposedVisibleRect.origin.y. adding adj (%d)", [self class], _cmd, adj); + newRect = NSMakeRect(newRect.origin.x, newRect.origin.y + adj, newRect.size.width, newRect.size.height); + } else if (sr.origin.y < proposedVisibleRect.origin.y) { + // NSLog(@"[%@ %s] selectedRow.origin.y < proposedVisibleRect.origin.y. subtracting ny (%d)", [self class], _cmd, ny); + newRect = NSMakeRect(newRect.origin.x, newRect.origin.y - ny , newRect.size.width, newRect.size.height); + } else { + // NSLog(@"[%@ %s] selectedRow.origin.y == proposedVisibleRect.origin.y. leaving as is", [self class], _cmd); + } + } + //NSLog(@"[%@ %s]: newRect: %@", [self class], _cmd, NSStringFromRect(newRect)); + return newRect; +} - (void)mouseDown:(NSEvent *)theEvent { diff --git a/PBGitHistoryController.h b/PBGitHistoryController.h index ba10842..3c92168 100644 --- a/PBGitHistoryController.h +++ b/PBGitHistoryController.h @@ -16,6 +16,7 @@ @class PBGitGradientBarView; @class PBRefController; @class QLPreviewPanel; +@class PBCommitList; @interface PBGitHistoryController : PBViewController { IBOutlet PBRefController *refController; @@ -24,7 +25,7 @@ IBOutlet NSTreeController* treeController; IBOutlet NSOutlineView* fileBrowser; NSArray *currentFileBrowserSelectionPath; - IBOutlet NSTableView* commitList; + IBOutlet PBCommitList* commitList; IBOutlet PBCollapsibleSplitView *historySplitView; QLPreviewPanel* previewPanel; diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index 8ff0b8c..9e0fafb 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -363,19 +363,26 @@ - (void) scrollSelectionToTopOfViewFrom:(NSInteger)oldIndex { - if (oldIndex == NSIntegerMax) + if (oldIndex == NSNotFound) oldIndex = 0; NSInteger newIndex = [[commitController selectionIndexes] firstIndex]; if (newIndex > oldIndex) { - NSInteger visibleRows = floorf([[commitList superview] bounds].size.height / [commitList rowHeight]); - newIndex += visibleRows - 1; + CGFloat sviewHeight = [[commitList superview] bounds].size.height; + CGFloat rowHeight = [commitList rowHeight]; + NSInteger visibleRows = roundf(sviewHeight / rowHeight ); + newIndex += (visibleRows - 1); if (newIndex >= [[commitController content] count]) newIndex = [[commitController content] count] - 1; } + if (newIndex != oldIndex) { + commitList.useAdjustScroll = YES; + } + [commitList scrollRowToVisible:newIndex]; + commitList.useAdjustScroll = NO; } - (NSArray *) selectedObjectsForSHA:(NSString *)commitSHA