Skip to content

Commit 52ec66d

Browse files
committed
Fix the first lines of a file hiding behind its tab bar (issue gitx#598)
Resizing a window left the file viewer stretched over the whole pane it shares with the Source, Blame and History bar, and the bar, drawn after it, covered the top of the file from then on. * Ask the controller which frame its web view is to occupy when a live resize ends, rather than handing it the whole pane * Answer that in the file view by stopping the viewer where the bar starts, so a bar laid out taller than the nib reserved for it takes the room from the viewer rather than from the file
1 parent dec174b commit 52ec66d

5 files changed

Lines changed: 87 additions & 1 deletion

File tree

‎Classes/Controllers/PBWebController.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@
2626

2727
- (WebScriptObject *)script;
2828
- (void)closeView;
29+
30+
- (NSRect)frameForWebView;
2931
@end

‎Classes/Controllers/PBWebController.m‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,12 @@ - (void)windowWillStartLiveResizeWithNotification:(NSNotification *)theNotificat
244244
- (void)windowDidEndLiveResizeWithNotification:(NSNotification *)theNotification
245245
{
246246
self.view.autoresizingMask = NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin | NSViewWidthSizable | NSViewHeightSizable;
247-
self.view.frame = self.view.superview.bounds;
247+
self.view.frame = [self frameForWebView];
248+
}
249+
250+
- (NSRect)frameForWebView
251+
{
252+
return self.view.superview.bounds;
248253
}
249254

250255
@end

‎Classes/Views/GLFileView.m‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ - (void)awakeFromNib
7373
[self performSelector:@selector(restoreSplitViewPositiion) withObject:nil afterDelay:0];
7474
}
7575

76+
- (NSRect)frameForWebView
77+
{
78+
NSRect frame = typeBar.superview.bounds;
79+
frame.size.height = NSMinY(typeBar.frame);
80+
81+
return frame;
82+
}
83+
7684
- (void)showFile
7785
{
7886
NSArray *files = [historyController.treeController selectedObjects];

‎GitX.xcodeproj/project.pbxproj‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
551BF176112F3F4B00265053 /* gitx_askpasswd in Resources */ = {isa = PBXBuildFile; fileRef = 551BF111112F371800265053 /* gitx_askpasswd */; };
155155
63E155858B2CC783EE10F1D7 /* PBGitRevListRaceConditionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 689D57B4A78CEF3B32EB0044 /* PBGitRevListRaceConditionTests.m */; };
156156
7A1C4E2B90D3F5A6C1B80011 /* PBGitRepositoryFetchArgumentsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A1C4E2B90D3F5A6C1B80012 /* PBGitRepositoryFetchArgumentsTests.m */; };
157+
6B2E70F3A19C4D5E8A730C90 /* GLFileViewLayoutTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B2E70F3A19C4D5E8A730C91 /* GLFileViewLayoutTests.m */; };
157158
63E155858B2CC783EE10F1D8 /* PBGitIndexReconcileTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 689D57B4A78CEF3B32EB0045 /* PBGitIndexReconcileTests.m */; };
158159
63E155858B2CC783EE10F1D9 /* PBGitIndexRefreshTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 689D57B4A78CEF3B32EB0046 /* PBGitIndexRefreshTests.m */; };
159160
7C41A9E2B5D340E1A7F26C08 /* PBGitHistorySelectionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E9D3B41C86F42A7B10D5E33 /* PBGitHistorySelectionTests.m */; };
@@ -696,6 +697,7 @@
696697
643952761603EF9B00BB7AFF /* PBSourceViewGitSubmoduleItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBSourceViewGitSubmoduleItem.m; sourceTree = "<group>"; };
697698
689D57B4A78CEF3B32EB0044 /* PBGitRevListRaceConditionTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRevListRaceConditionTests.m; path = GitXTests/PBGitRevListRaceConditionTests.m; sourceTree = "<group>"; };
698699
7A1C4E2B90D3F5A6C1B80012 /* PBGitRepositoryFetchArgumentsTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRepositoryFetchArgumentsTests.m; path = GitXTests/PBGitRepositoryFetchArgumentsTests.m; sourceTree = "<group>"; };
700+
6B2E70F3A19C4D5E8A730C91 /* GLFileViewLayoutTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = GLFileViewLayoutTests.m; path = GitXTests/GLFileViewLayoutTests.m; sourceTree = "<group>"; };
699701
689D57B4A78CEF3B32EB0045 /* PBGitIndexReconcileTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitIndexReconcileTests.m; path = GitXTests/PBGitIndexReconcileTests.m; sourceTree = "<group>"; };
700702
689D57B4A78CEF3B32EB0046 /* PBGitIndexRefreshTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitIndexRefreshTests.m; path = GitXTests/PBGitIndexRefreshTests.m; sourceTree = "<group>"; };
701703
5E9D3B41C86F42A7B10D5E33 /* PBGitHistorySelectionTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitHistorySelectionTests.m; path = GitXTests/PBGitHistorySelectionTests.m; sourceTree = "<group>"; };
@@ -824,6 +826,7 @@
824826
children = (
825827
689D57B4A78CEF3B32EB0044 /* PBGitRevListRaceConditionTests.m */,
826828
7A1C4E2B90D3F5A6C1B80012 /* PBGitRepositoryFetchArgumentsTests.m */,
829+
6B2E70F3A19C4D5E8A730C91 /* GLFileViewLayoutTests.m */,
827830
689D57B4A78CEF3B32EB0045 /* PBGitIndexReconcileTests.m */,
828831
689D57B4A78CEF3B32EB0046 /* PBGitIndexRefreshTests.m */,
829832
5E9D3B41C86F42A7B10D5E33 /* PBGitHistorySelectionTests.m */,
@@ -1767,6 +1770,7 @@
17671770
files = (
17681771
63E155858B2CC783EE10F1D7 /* PBGitRevListRaceConditionTests.m in Sources */,
17691772
7A1C4E2B90D3F5A6C1B80011 /* PBGitRepositoryFetchArgumentsTests.m in Sources */,
1773+
6B2E70F3A19C4D5E8A730C90 /* GLFileViewLayoutTests.m in Sources */,
17701774
63E155858B2CC783EE10F1D8 /* PBGitIndexReconcileTests.m in Sources */,
17711775
63E155858B2CC783EE10F1D9 /* PBGitIndexRefreshTests.m in Sources */,
17721776
7C41A9E2B5D340E1A7F26C08 /* PBGitHistorySelectionTests.m in Sources */,

‎GitXTests/GLFileViewLayoutTests.m‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// GLFileViewLayoutTests.m
3+
// GitXTests
4+
//
5+
6+
#import <XCTest/XCTest.h>
7+
#import "GLFileView.h"
8+
9+
// The type bar is an outlet, so a test has to hand it over itself. Only the
10+
// room it takes up matters here, which any view can stand in for.
11+
@interface PBLayoutStubFileView : GLFileView
12+
- (void)useTypeBar:(id)bar;
13+
@end
14+
15+
@implementation PBLayoutStubFileView
16+
17+
- (void)useTypeBar:(id)bar
18+
{
19+
typeBar = bar;
20+
}
21+
22+
@end
23+
24+
@interface GLFileViewLayoutTests : XCTestCase
25+
@property (nonatomic, strong) NSView *container;
26+
@property (nonatomic, strong) NSView *typeBar;
27+
@property (nonatomic, strong) PBLayoutStubFileView *fileView;
28+
@end
29+
30+
@implementation GLFileViewLayoutTests
31+
32+
- (void)buildViewerOfHeight:(CGFloat)height barHeight:(CGFloat)barHeight
33+
{
34+
self.container = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 400, height)];
35+
self.typeBar = [[NSView alloc] initWithFrame:NSMakeRect(0, height - barHeight, 400, barHeight)];
36+
[self.container addSubview:self.typeBar];
37+
38+
self.fileView = [[PBLayoutStubFileView alloc] init];
39+
[self.fileView useTypeBar:self.typeBar];
40+
}
41+
42+
- (void)testTheViewerStopsWhereTheTypeBarStarts
43+
{
44+
[self buildViewerOfHeight:214 barHeight:25];
45+
46+
NSRect frame = [self.fileView frameForWebView];
47+
48+
XCTAssertEqual(NSMaxY(frame), 189.0, @"the file has to end below the bar, not behind it");
49+
XCTAssertEqual(NSMinY(frame), 0.0);
50+
XCTAssertEqual(NSWidth(frame), 400.0, @"the whole width is still the viewer's to use");
51+
}
52+
53+
- (void)testTheViewerFollowsTheContainerItSitsIn
54+
{
55+
[self buildViewerOfHeight:900 barHeight:25];
56+
57+
XCTAssertEqual(NSMaxY([self.fileView frameForWebView]), 875.0, @"a resized window leaves the bar where it is");
58+
}
59+
60+
- (void)testATallerTypeBarTakesItsOwnRoom
61+
{
62+
[self buildViewerOfHeight:214 barHeight:46];
63+
64+
XCTAssertEqual(NSMaxY([self.fileView frameForWebView]), 168.0);
65+
}
66+
67+
@end

0 commit comments

Comments
 (0)