Skip to content
Browse files

Sort the results using insertion as results appear rather than re-sor…

…ting.
  • Loading branch information...
1 parent 68429a2 commit e208fc0828a9df0a7e8d3a4a99bea1b6433a0502 @beelsebob committed Dec 24, 2012
Showing with 10 additions and 3 deletions.
  1. +10 −3 Stash/STAAppDelegate.m
View
13 Stash/STAAppDelegate.m
@@ -22,7 +22,7 @@ @interface STAAppDelegate () <NSWindowDelegate>
@property (assign,getter=isWaitingForDocsetInput) BOOL waitingForDocsetInput;
@property (copy) NSString *currentSearchString;
@property (strong) NSMutableArray *results;
-@property (strong) NSArray *sortedResults;
+@property (strong) NSMutableArray *sortedResults;
@property (assign, getter=isFindUIShowing) BOOL findUIShowing;
@property (weak) NSSearchField *selectedSearchField;
@@ -522,7 +522,7 @@ - (IBAction)search:(id)sender
[self hideSearchBar:self];
[self setCurrentSearchString:searchString];
[self setResults:[NSMutableArray array]];
- [self setSortedResults:[NSArray array]];
+ [self setSortedResults:[NSMutableArray array]];
[[self resultsTable] reloadData];
for (STADocSet *docSet in [[self preferencesController] enabledDocsets])
{
@@ -539,7 +539,14 @@ - (IBAction)search:(id)sender
if ([searchString isEqualToString:[self currentSearchString]])
{
[[self results] addObject:symbol];
- [self setSortedResults:[[self results] sortedArrayUsingSelector:@selector(compare:)]];
+ [[self sortedResults] insertObject:symbol
+ atIndex:[[self sortedResults] indexOfObject:symbol
+ inSortedRange:NSMakeRange(0, [[self sortedResults] count])
+ options:NSBinarySearchingInsertionIndex
+ usingComparator:^ NSComparisonResult (id a, id b)
+ {
+ return [a compare:b];
+ }]];
[[self resultsTable] insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:[[self sortedResults] indexOfObject:symbol]] withAnimation:0];
if ([[self resultsTable] selectedRow] != 0)
{

0 comments on commit e208fc0

Please sign in to comment.
Something went wrong with that request. Please try again.