Skip to content

Commit fb425f5

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 b621306 commit fb425f5

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
@@ -155,6 +155,7 @@
155155
63E155858B2CC783EE10F1D7 /* PBGitRevListRaceConditionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 689D57B4A78CEF3B32EB0044 /* PBGitRevListRaceConditionTests.m */; };
156156
7A1C4E2B90D3F5A6C1B80011 /* PBGitRepositoryFetchArgumentsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A1C4E2B90D3F5A6C1B80012 /* PBGitRepositoryFetchArgumentsTests.m */; };
157157
3D8A5F14C7E9420B96741C80 /* PBGitRepositoryIgnoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D8A5F14C7E9420B96741C81 /* PBGitRepositoryIgnoreTests.m */; };
158+
6B2E70F3A19C4D5E8A730C90 /* GLFileViewLayoutTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B2E70F3A19C4D5E8A730C91 /* GLFileViewLayoutTests.m */; };
158159
63E155858B2CC783EE10F1D8 /* PBGitIndexReconcileTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 689D57B4A78CEF3B32EB0045 /* PBGitIndexReconcileTests.m */; };
159160
63E155858B2CC783EE10F1D9 /* PBGitIndexRefreshTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 689D57B4A78CEF3B32EB0046 /* PBGitIndexRefreshTests.m */; };
160161
9A3F7C21E48B450D9C2A1F60 /* PBGitIndexDiffCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A3F7C21E48B450D9C2A1F61 /* PBGitIndexDiffCacheTests.m */; };
@@ -699,6 +700,7 @@
699700
689D57B4A78CEF3B32EB0044 /* PBGitRevListRaceConditionTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRevListRaceConditionTests.m; path = GitXTests/PBGitRevListRaceConditionTests.m; sourceTree = "<group>"; };
700701
7A1C4E2B90D3F5A6C1B80012 /* PBGitRepositoryFetchArgumentsTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRepositoryFetchArgumentsTests.m; path = GitXTests/PBGitRepositoryFetchArgumentsTests.m; sourceTree = "<group>"; };
701702
3D8A5F14C7E9420B96741C81 /* PBGitRepositoryIgnoreTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRepositoryIgnoreTests.m; path = GitXTests/PBGitRepositoryIgnoreTests.m; sourceTree = "<group>"; };
703+
6B2E70F3A19C4D5E8A730C91 /* GLFileViewLayoutTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = GLFileViewLayoutTests.m; path = GitXTests/GLFileViewLayoutTests.m; sourceTree = "<group>"; };
702704
689D57B4A78CEF3B32EB0045 /* PBGitIndexReconcileTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitIndexReconcileTests.m; path = GitXTests/PBGitIndexReconcileTests.m; sourceTree = "<group>"; };
703705
689D57B4A78CEF3B32EB0046 /* PBGitIndexRefreshTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitIndexRefreshTests.m; path = GitXTests/PBGitIndexRefreshTests.m; sourceTree = "<group>"; };
704706
9A3F7C21E48B450D9C2A1F61 /* PBGitIndexDiffCacheTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitIndexDiffCacheTests.m; path = GitXTests/PBGitIndexDiffCacheTests.m; sourceTree = "<group>"; };
@@ -829,6 +831,7 @@
829831
689D57B4A78CEF3B32EB0044 /* PBGitRevListRaceConditionTests.m */,
830832
7A1C4E2B90D3F5A6C1B80012 /* PBGitRepositoryFetchArgumentsTests.m */,
831833
3D8A5F14C7E9420B96741C81 /* PBGitRepositoryIgnoreTests.m */,
834+
6B2E70F3A19C4D5E8A730C91 /* GLFileViewLayoutTests.m */,
832835
689D57B4A78CEF3B32EB0045 /* PBGitIndexReconcileTests.m */,
833836
689D57B4A78CEF3B32EB0046 /* PBGitIndexRefreshTests.m */,
834837
9A3F7C21E48B450D9C2A1F61 /* PBGitIndexDiffCacheTests.m */,
@@ -1774,6 +1777,7 @@
17741777
63E155858B2CC783EE10F1D7 /* PBGitRevListRaceConditionTests.m in Sources */,
17751778
7A1C4E2B90D3F5A6C1B80011 /* PBGitRepositoryFetchArgumentsTests.m in Sources */,
17761779
3D8A5F14C7E9420B96741C80 /* PBGitRepositoryIgnoreTests.m in Sources */,
1780+
6B2E70F3A19C4D5E8A730C90 /* GLFileViewLayoutTests.m in Sources */,
17771781
63E155858B2CC783EE10F1D8 /* PBGitIndexReconcileTests.m in Sources */,
17781782
63E155858B2CC783EE10F1D9 /* PBGitIndexRefreshTests.m in Sources */,
17791783
9A3F7C21E48B450D9C2A1F60 /* PBGitIndexDiffCacheTests.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)