From 9327e56cf8674a8f47d7ff9a9019055993fa22fb Mon Sep 17 00:00:00 2001 From: Thomas Goddard Date: Wed, 26 Oct 2016 17:23:10 -0700 Subject: [PATCH 1/2] Fix crash when _revision.document is nil on save --- Source/DocEditor.m | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Source/DocEditor.m b/Source/DocEditor.m index 184fd08..26f24a0 100644 --- a/Source/DocEditor.m +++ b/Source/DocEditor.m @@ -124,7 +124,7 @@ - (BOOL) saveDocument { if (!_readOnly && _root && ![properties isEqual: _revision.properties]) { CBLDocument* doc; NSError* error; - if (_revision) + if (_revision.document) doc = _revision.document; else doc = _db[properties[@"_id"]]; @@ -166,7 +166,7 @@ - (IBAction) addProperty: (id)sender { } else { parent = sibling.parent; } - + JSONItem *newItem = [parent createChildBefore: sibling]; if (!newItem) { NSBeep(); @@ -266,8 +266,8 @@ - (void) enablePropertyButtons { - (id) outlineView: (NSOutlineView *)outlineView - objectValueForTableColumn: (NSTableColumn *)tableColumn - byItem: (JSONItem*)item +objectValueForTableColumn: (NSTableColumn *)tableColumn + byItem: (JSONItem*)item { if ([tableColumn.identifier isEqualToString: @"key"]) { return item.key; @@ -311,8 +311,8 @@ - (void)outlineView: (NSOutlineView *)outlineView - (BOOL)outlineView:(NSOutlineView *)outlineView - shouldEditTableColumn:(NSTableColumn *)tableColumn - item: (JSONItem*)item +shouldEditTableColumn:(NSTableColumn *)tableColumn + item: (JSONItem*)item { BOOL isKeyColumn = [tableColumn.identifier isEqualToString: @"key"]; if (_readOnly) @@ -350,7 +350,7 @@ - (void) outlineView: (NSOutlineView*)outlineView return; if (item.isSpecial && !_untitled) return; - + if (newCellValue == nil || [newCellValue isEqual: @""]) { // User entered empty key or value: delete property JSONItem* parent = item.parent; @@ -368,8 +368,8 @@ - (void) outlineView: (NSOutlineView*)outlineView - (BOOL) control: (NSControl*)control - didFailToFormatString: (NSString*)string - errorDescription: (NSString*)errorMessage +didFailToFormatString: (NSString*)string +errorDescription: (NSString*)errorMessage { if (_cancelingEdit) return YES; @@ -382,9 +382,9 @@ - (BOOL) control: (NSControl*)control [alert addButtonWithTitle: @"Cancel"]; [alert beginSheetModalForWindow: control.window completionHandler:^(NSModalResponse returnCode) { - if (returnCode == NSAlertSecondButtonReturn) - [self cancelOperation: self]; - }]; + if (returnCode == NSAlertSecondButtonReturn) + [self cancelOperation: self]; + }]; } return NO; } @@ -397,7 +397,7 @@ - (void)outlineViewSelectionDidChange:(NSNotification *)notification { - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView - doCommandBySelector:(SEL)command +doCommandBySelector:(SEL)command { //NSLog(@"command: %@", NSStringFromSelector(command)); if (command == @selector(cancelOperation:)) { // Esc key From e23fe00c3fc6491fe31090b059ee97ca211ba6e1 Mon Sep 17 00:00:00 2001 From: Thomas Goddard Date: Wed, 26 Oct 2016 17:25:35 -0700 Subject: [PATCH 2/2] Add check for revision first, and then document --- Source/DocEditor.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DocEditor.m b/Source/DocEditor.m index 26f24a0..34fb2e4 100644 --- a/Source/DocEditor.m +++ b/Source/DocEditor.m @@ -124,7 +124,7 @@ - (BOOL) saveDocument { if (!_readOnly && _root && ![properties isEqual: _revision.properties]) { CBLDocument* doc; NSError* error; - if (_revision.document) + if (_revision && _revision.document) doc = _revision.document; else doc = _db[properties[@"_id"]];