Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

When clearing search field, select the last search results

  • Loading branch information...
commit 098125d4921a2e837bcb9764290ffcc54bc7d7b5 1 parent 46203e3
@sleifer authored
Showing with 20 additions and 1 deletion.
  1. +2 −0  PBGitHistoryController.h
  2. +18 −1 PBGitHistoryController.m
View
2  PBGitHistoryController.h
@@ -54,6 +54,7 @@
PBGitTree *gitTree;
PBGitCommit *webCommit;
PBGitCommit *selectedCommit;
+ NSArray *lastSearchSelection;
}
@property (assign) int selectedCommitDetailsIndex;
@@ -61,6 +62,7 @@
@property (retain) PBGitTree* gitTree;
@property (readonly) NSArrayController *commitController;
@property (readonly) PBRefController *refController;
+@property (retain) NSArray *lastSearchSelection;
- (IBAction) setDetailedView:(id)sender;
- (IBAction) setTreeView:(id)sender;
View
19 PBGitHistoryController.m
@@ -39,7 +39,8 @@ - (void) saveFileBrowserSelection;
@implementation PBGitHistoryController
-@synthesize selectedCommitDetailsIndex, webCommit, gitTree, commitController, refController;
+
+@synthesize selectedCommitDetailsIndex, webCommit, gitTree, commitController, refController, lastSearchSelection;
- (void)awakeFromNib
{
@@ -47,6 +48,7 @@ - (void)awakeFromNib
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.PBUseRelativeDates" options:NSKeyValueObservingOptionNew context:@"relativeDates"];
[commitController addObserver:self forKeyPath:@"selection" options:0 context:@"commitChange"];
+ [commitController addObserver:self forKeyPath:@"filterPredicate" options:0 context:@"filterChange"];
[commitController addObserver:self forKeyPath:@"arrangedObjects.@count" options:NSKeyValueObservingOptionInitial context:@"updateCommitCount"];
[treeController addObserver:self forKeyPath:@"selection" options:0 context:@"treeChange"];
@@ -244,6 +246,21 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
return;
}
+ if ([(NSString *)context isEqualToString: @"filterChange"]) {
+ int count = [[commitController arrangedObjects] count];
+
+ if (count > 0 && [[searchField stringValue] length] != 0) {
+ lastSearchSelection = [NSArray arrayWithArray:[commitController arrangedObjects]];
+ } else if (count > 0 && [[searchField stringValue] length] == 0) {
+ [commitController setSelectedObjects:lastSearchSelection];
+ NSInteger newIndex = [[commitController selectionIndexes] firstIndex];
+ [commitList scrollRowToVisible:newIndex];
+ } else {
+ lastSearchSelection = nil;
+ }
+ return;
+ }
+
if ([(NSString*)context isEqualToString:@"relativeDates"]) {
[commitList reloadData];
return;
Please sign in to comment.
Something went wrong with that request. Please try again.