Bug fix: correct visible index scrolling in PBGitHistoryController and PBCommitList.

If the current branch filter is switched to "All" or "Local" the index that's
calculated as being the targeted index to scroll to visible, is off by the amount
in Y that the bottom split view separator is off from a multiple of rows.

-adjustScroll: on PBCommitList is called automatically whenever the list needs 
laying out. 
An ivar keeps track if we come from the -scrollSelectionToTopOfViewFrom: method
of PBGitHistoryController.

I'll leave the commented out NSLogs in there in case they're needed for debugging
again later.
This commit is contained in:
André Berg
2010-04-05 16:32:59 +02:00
parent ba63642c87
commit 5cb73b4d42
3 changed files with 49 additions and 4 deletions
+2 -1
View File
@@ -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
+35
View File
@@ -13,6 +13,8 @@
@implementation PBCommitList
@synthesize mouseDownPoint;
@synthesize useAdjustScroll;
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL) local
{
return NSDragOperationCopy;
@@ -47,6 +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
{
+12 -3
View File
@@ -385,19 +385,28 @@
- (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;
}
NSLog(@"[%@ %s] newIndex = %d, oldIndex = %d", [self class], _cmd, newIndex, oldIndex);
[commitList scrollRowToVisible:newIndex];
commitList.useAdjustScroll = NO;
}
- (NSArray *) selectedObjectsForSHA:(NSString *)commitSHA