Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MacDown/Code/Document/MPDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,10 @@ - (IBAction)togglePreviewPane:(id)sender

- (IBAction)toggleEditorPane:(id)sender
{
BOOL wasVisible = self.editorVisible;
[self toggleSplitterCollapsingEditorPane:YES];
if (self.editorVisible != wasVisible)
self.preferences.editorStartInPreviewMode = !self.editorVisible;
}

- (IBAction)toggleAutoSave:(id)sender
Expand Down
40 changes: 40 additions & 0 deletions MacDownTests/MPPaneToggleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ @implementation MockMenuItem

@interface MPPaneToggleTests : XCTestCase
@property (strong) MPDocument *document;
@property BOOL originalStartInPreviewMode;
@end


Expand All @@ -51,12 +52,17 @@ @implementation MPPaneToggleTests
- (void)setUp
{
[super setUp];
MPPreferences *preferences = [MPPreferences sharedInstance];
self.originalStartInPreviewMode = preferences.editorStartInPreviewMode;
preferences.editorStartInPreviewMode = NO;
self.document = [[MPDocument alloc] init];
}

- (void)tearDown
{
self.document = nil;
[MPPreferences sharedInstance].editorStartInPreviewMode =
self.originalStartInPreviewMode;
[super tearDown];
}

Expand All @@ -83,6 +89,40 @@ - (void)testTogglePreviewPaneIBActionDoesNotCrash
@"togglePreviewPane: should not crash");
}

- (void)testEditorPaneChoiceIsRemembered
{
MPPreferences *preferences = [MPPreferences sharedInstance];
BOOL originalEditorOnRight = preferences.editorOnRight;

@try {
MPDocumentSplitView *splitView = [[MPDocumentSplitView alloc]
initWithFrame:NSMakeRect(0, 0, 800, 600)];
splitView.vertical = YES;
NSView *editor = [[NSView alloc]
initWithFrame:NSMakeRect(0, 0, 399, 600)];
WebView *preview = [[WebView alloc]
initWithFrame:NSMakeRect(400, 0, 400, 600)];
[splitView addSubview:editor];
[splitView addSubview:preview];

self.document.splitView = splitView;
self.document.editorContainer = editor;
self.document.preview = preview;
preferences.editorOnRight = NO;

[self.document toggleEditorPane:nil];
XCTAssertTrue(preferences.editorStartInPreviewMode,
@"Hiding the editor should be remembered for the next window");

[self.document toggleEditorPane:nil];
XCTAssertFalse(preferences.editorStartInPreviewMode,
@"Restoring the editor should update the remembered choice");
}
@finally {
preferences.editorOnRight = originalEditorOnRight;
}
}


#pragma mark - Menu Validation Tests

Expand Down