mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
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:
committed by
Nathan Kinsinger
parent
a7106ba60d
commit
969ff24ac7
+2
-1
@@ -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
-1
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user