Skip to content

Commit

Permalink
Damn, smartcmp is clever. Good dog.
Browse files Browse the repository at this point in the history
  • Loading branch information
atg committed Jul 1, 2010
1 parent ccfd527 commit 8457248
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 23 deletions.
26 changes: 8 additions & 18 deletions CHDocumentationBrowser.xib
Expand Up @@ -23,15 +23,15 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="114"/>
<integer value="759"/>
<integer value="189"/>
<integer value="63"/>
<integer value="20"/>
<integer value="1"/>
<integer value="19"/>
<integer value="114"/>
<integer value="42"/>
<integer value="820"/>
<integer value="189"/>
<integer value="373"/>
<integer value="63"/>
<integer value="820"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand Down Expand Up @@ -438,7 +438,6 @@
<int key="NSvFlags">-2147483392</int>
<string key="NSFrame">{{0, 337}, {620, 15}}</string>
<reference key="NSSuperview" ref="61344541"/>
<bool key="NSEnabled">YES</bool>
<int key="NSsFlags">1</int>
<reference key="NSTarget" ref="61344541"/>
<string key="NSAction">_doScroller:</string>
Expand All @@ -463,7 +462,7 @@
<string key="NSFrameSize">{635, 340}</string>
<reference key="NSSuperview" ref="3414012"/>
<reference key="NSNextKeyView" ref="770639792"/>
<int key="NSsFlags">688</int>
<int key="NSsFlags">560</int>
<reference key="NSVScroller" ref="837312541"/>
<reference key="NSHScroller" ref="1055726284"/>
<reference key="NSContentView" ref="770639792"/>
Expand Down Expand Up @@ -3329,15 +3328,7 @@
</object>
<double key="NSIntercellSpacingWidth">3</double>
<double key="NSIntercellSpacingHeight">2</double>
<object class="NSColor" key="NSBackgroundColor">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">_sourceListBackgroundColor</string>
<object class="NSColor" key="NSColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC44MzkyMTU2OTU5IDAuODY2NjY2Njc0NiAwLjg5ODAzOTIyMTgAA</bytes>
</object>
</object>
<reference key="NSBackgroundColor" ref="936577122"/>
<reference key="NSGridColor" ref="365060459"/>
<double key="NSRowHeight">17</double>
<int key="NSTvFlags">314572800</int>
Expand All @@ -3347,8 +3338,7 @@
<int key="NSDraggingSourceMaskForLocal">15</int>
<int key="NSDraggingSourceMaskForNonLocal">0</int>
<bool key="NSAllowsTypeSelect">NO</bool>
<int key="NSTableViewSelectionHighlightStyle">1</int>
<int key="NSTableViewDraggingDestinationStyle">1</int>
<int key="NSTableViewDraggingDestinationStyle">0</int>
</object>
</object>
<string key="NSFrameSize">{247, 350}</string>
Expand Down
56 changes: 56 additions & 0 deletions IGKWindowController.m
Expand Up @@ -926,9 +926,52 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBy

}
}
else if (control == rightFilterBarSearchField)
{
if ([NSStringFromSelector(command) isEqual:@"moveUp:"] || [NSStringFromSelector(command) isEqual:@"moveDown:"])
{
[self performSelector:@selector(handleRightFilterBarEvent:) withObject:NSStringFromSelector(command) afterDelay:0.3];
return YES;
}
}

return NO;
}
- (void)handleRightFilterBarEvent:(NSString *)command
{
if ([command isEqual:@"moveUp:"])
{
NSInteger i = [rightFilterBarTable selectedRow] - 1;
while (i >= 0 && i < [rightFilterBarTable numberOfRows])
{
BOOL canSelect = [[rightFilterBarTable delegate] tableView:rightFilterBarTable shouldSelectRow:i];
if (canSelect)
{
[rightFilterBarTable selectRowIndexes:[NSIndexSet indexSetWithIndex:i] byExtendingSelection:NO];
[rightFilterBarTable scrollRowToVisible:i];
break;
}

i--;
}
}
else if ([command isEqual:@"moveDown:"])
{
NSInteger i = [rightFilterBarTable selectedRow] + 1;
while (i < [rightFilterBarTable numberOfRows] && i < [rightFilterBarTable numberOfRows])
{
BOOL canSelect = [[rightFilterBarTable delegate] tableView:rightFilterBarTable shouldSelectRow:i];
if (canSelect)
{
[rightFilterBarTable selectRowIndexes:[NSIndexSet indexSetWithIndex:i] byExtendingSelection:NO];
[rightFilterBarTable scrollRowToVisible:i];
break;
}

i++;
}
}
}

- (IBAction)changeSelectedFilterDocset:(id)sender
{
Expand Down Expand Up @@ -1393,6 +1436,19 @@ - (IBAction)rightFilterSearchField:(id)sender
}

[rightFilterBarTable reloadData];

//Select the best matching item, as selected by smartSort:
NSArray *smartSorted = [[rightFilterBarItems igk_filter:^(id obj) { return [obj respondsToSelector:@selector(keyEnumerator)]; }] smartSort:queryString];
if ([smartSorted count])
{
NSUInteger smartIndex = [rightFilterBarItems indexOfObject:[smartSorted igk_firstObject]];
if (smartIndex < NSNotFound && smartIndex > 0 && smartIndex < [rightFilterBarTable numberOfRows] && [[rightFilterBarTable delegate] tableView:rightFilterBarTable shouldSelectRow:smartIndex])
{
[rightFilterBarTable selectRowIndexes:[NSIndexSet indexSetWithIndex:smartIndex] byExtendingSelection:NO];
[rightFilterBarTable scrollRowToVisible:smartIndex];
[[rightFilterBarTable delegate] tableViewSelectionDidChange:[NSNotification notificationWithName:NSTableViewSelectionDidChangeNotification object:rightFilterBarTable]];
}
}
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
Expand Down
2 changes: 1 addition & 1 deletion NSArray+IGKAdditions.m
Expand Up @@ -46,7 +46,7 @@ - (NSArray *)igk_objectAtSoftIndex:(NSInteger)index
if (index < 0)
return [self igk_objectAtSoftIndex:[self count] + index];

if (index > [self count])
if (index >= [self count])
return nil;

return [self objectAtIndex:index];
Expand Down
1 change: 0 additions & 1 deletion Remaining bugs.txt
@@ -1,5 +1,4 @@
When typing in the right filter search field, the best match (selected by smartcmp) should be selected and the webview should scroll to its anchor
Should be able to use up/down arrow keys while filter bar search field is first responder to navigate the filter bar
The webview shouldn't scroll when resizing: Let x be the number of pixels to the nearest anchor, then x should be invariant when resizing.
Needs key combos for selecting the next and previous method in the webview
Switch to smartcmp algorithm
Expand Down
9 changes: 6 additions & 3 deletions smartcmp.m
Expand Up @@ -144,9 +144,12 @@ SmartCmpScore categoryScore(id resultObject)
int categoryCount = 1;

//Priority
SmartCmpScore maximumPriorityValue = (SmartCmpScore)(CHPriorityMaximum - 1);
score += ((SmartCmpScore)[resultObject priorityval]) / maximumPriorityValue;

if ([resultObject respondsToSelector:@selector(priorityval)])
{
SmartCmpScore maximumPriorityValue = (SmartCmpScore)(CHPriorityMaximum - 1);
score += ((SmartCmpScore)[resultObject priorityval]) / maximumPriorityValue;
}

//Docsets
//TODO: Record most used docsets and score appropriately

Expand Down

0 comments on commit 8457248

Please sign in to comment.