diff --git a/MacPass/MPDocument+Search.m b/MacPass/MPDocument+Search.m index 7da1e04c..f7a10afe 100644 --- a/MacPass/MPDocument+Search.m +++ b/MacPass/MPDocument+Search.m @@ -42,11 +42,11 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul - (void)enterSearchWithContext:(MPEntrySearchContext *)context { /* the search context is loaded via defaults */ self.searchContext = context; - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:NSUndoManagerDidRedoChangeNotification object:self.undoManager]; - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:NSUndoManagerDidUndoChangeNotification object:self.undoManager]; - /* Do not do this since it seems to break the undo/redo grouping completly! - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:NSUndoManagerDidCloseUndoGroupNotification object:self.undoManager]; - */ + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:KPKTreeDidAddEntryNotification object:self.tree]; + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:KPKTreeDidAddGroupNotification object:self.tree]; + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:KPKTreeDidRemoveEntryNotification object:self.tree]; + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:KPKTreeDidRemoveGroupNotification object:self.tree]; + [NSNotificationCenter.defaultCenter postNotificationName:MPDocumentDidEnterSearchNotification object:self]; [self updateSearch:self]; /* clear selection */ @@ -77,11 +77,12 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul } - (void)exitSearch:(id)sender { - [NSNotificationCenter.defaultCenter removeObserver:self name:NSUndoManagerDidUndoChangeNotification object:self.undoManager]; - [NSNotificationCenter.defaultCenter removeObserver:self name:NSUndoManagerDidRedoChangeNotification object:self.undoManager]; - /* No need to do this since we did not register in the first place see [MPDocument enterSearchWithContext:] - [NSNotificationCenter.defaultCenter removeObserver:self name:NSUndoManagerDidCloseUndoGroupNotification object:self.undoManager]; - */ + + [NSNotificationCenter.defaultCenter removeObserver:self name:KPKTreeDidAddEntryNotification object:self.tree]; + [NSNotificationCenter.defaultCenter removeObserver:self name:KPKTreeDidAddGroupNotification object:self.tree]; + [NSNotificationCenter.defaultCenter removeObserver:self name:KPKTreeDidRemoveEntryNotification object:self.tree]; + [NSNotificationCenter.defaultCenter removeObserver:self name:KPKTreeDidRemoveGroupNotification object:self.tree]; + self.searchContext = nil; [NSNotificationCenter.defaultCenter postNotificationName:MPDocumentDidExitSearchNotification object:self]; } diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 456273b1..790b9624 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -76,7 +76,6 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; } @property (strong) MPContextBarViewController *contextBarViewController; -@property (strong) NSArray *filteredEntries; @property (weak) IBOutlet NSTableView *entryTable; @property (assign) MPDisplayMode displayMode; @@ -502,8 +501,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; - (void)_didUpdateSearchResults:(NSNotification *)notification { NSArray *result = notification.userInfo[kMPDocumentSearchResultsKey]; NSAssert(result != nil, @"Results should never be nil"); - self.filteredEntries = result; - self.entryArrayController.content = self.filteredEntries; + self.entryArrayController.content = result; [self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier].hidden = NO; [self _updateContextBar]; } @@ -512,7 +510,6 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; - (void)_didExitSearch:(NSNotification *)notification { [self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier].hidden = YES; self.entryArrayController.content = nil; - self.filteredEntries = nil; self.displayMode = MPDisplayModeEntries; [self _updateContextBar]; MPDocument *document = notification.object;