From 59f4fd0ae0042654df2f8afb95e0e2336f5973b3 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Mon, 14 Nov 2022 09:42:53 +0100 Subject: [PATCH] adde re-selection of groups when exiting search. --- MacPass/MPDocument+Search.m | 1 - MacPass/MPOutlineViewController.m | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/MacPass/MPDocument+Search.m b/MacPass/MPDocument+Search.m index 19a77822..0d263c64 100644 --- a/MacPass/MPDocument+Search.m +++ b/MacPass/MPDocument+Search.m @@ -50,7 +50,6 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul [NSNotificationCenter.defaultCenter postNotificationName:MPDocumentDidEnterSearchNotification object:self]; [self updateSearch:self]; /* clear selection */ - self.selectedGroups = nil; self.selectedEntries = nil; } diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index ea6e8465..8d6239bb 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -46,6 +46,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; @interface MPOutlineViewController () { BOOL _bindingEstablished; + NSIndexSet *_storedSelectionIndexSet; MPOutlineContextMenuDelegate *_menuDelegate; } @@ -100,7 +101,6 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; name:MPDidActivateViewNotification object:self.outlineView]; - NSView *clipView = self.outlineView.enclosingScrollView.contentView; [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_outlineDidScroll:) @@ -226,6 +226,8 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; - (void)registerNotificationsForDocument:(MPDocument *)document { [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didAddGroup:) name:MPDocumentDidAddGroupNotification object:document]; [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didRevertDocument:) name:MPDocumentDidRevertNotification object:document]; + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didEnterSearch:) name:MPDocumentDidEnterSearchNotification object:document]; + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didExitSearch:) name:MPDocumentDidExitSearchNotification object:document]; } - (void)clearSelection { @@ -273,6 +275,16 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; [self clearSelection]; } +- (void)_didEnterSearch:(NSNotification *)notification { + // store seelection + _storedSelectionIndexSet = self.outlineView.selectedRowIndexes; + [self clearSelection]; +} + +- (void)_didExitSearch:(NSNotification *)notification { + [self.outlineView selectRowIndexes:_storedSelectionIndexSet byExtendingSelection:NO]; +} + - (id)itemUnderMouse { NSPoint mouseLocation = [self.outlineView.window mouseLocationOutsideOfEventStream]; NSPoint localPoint = [self.outlineView convertPoint:mouseLocation fromView:self.outlineView.window.contentView];