mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 15:30:18 +00:00
Better file view search
This commit is contained in:
+1
-8
@@ -639,14 +639,7 @@
|
||||
|
||||
-(IBAction)updateSearch:(NSSearchField *)sender
|
||||
{
|
||||
NSString *searchString = [sender stringValue];
|
||||
DLog(@"searchString:%@",searchString);
|
||||
|
||||
if([searchString length]>0){
|
||||
[view highlightAllOccurencesOfString:searchString];
|
||||
}else{
|
||||
[view removeAllHighlights];
|
||||
}
|
||||
[view updateSearch:sender];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
+909
-28
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -11,8 +11,9 @@
|
||||
|
||||
@interface WebView (SearchWebView)
|
||||
|
||||
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str;
|
||||
- (DOMRange *)highlightAllOccurencesOfString:(NSString*)str;
|
||||
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str inNode:(DOMNode *)node;
|
||||
- (void)removeAllHighlights;
|
||||
- (void)updateSearch:(NSSearchField *)sender;
|
||||
|
||||
@end
|
||||
|
||||
+26
-2
@@ -50,19 +50,43 @@
|
||||
return count;
|
||||
}
|
||||
|
||||
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str
|
||||
- (DOMRange *)highlightAllOccurencesOfString:(NSString*)str
|
||||
{
|
||||
NSInteger count=0;
|
||||
DOMRange *res=nil;
|
||||
|
||||
if([[[[self mainFrame] DOMDocument] documentElement] isKindOfClass:[DOMHTMLElement class]]){
|
||||
DOMHTMLElement *dom=(DOMHTMLElement *)[[[self mainFrame] DOMDocument] documentElement];
|
||||
if(![str isEqualToString:[dom getAttribute:@"searchStr"]]){
|
||||
[self removeAllHighlights];
|
||||
count=[self highlightAllOccurencesOfString:str inNode:dom];
|
||||
if(count>0){
|
||||
[dom setAttribute:@"searchStr" value:str];
|
||||
}
|
||||
}
|
||||
if([self searchFor:str direction:YES caseSensitive:NO wrap:YES]){
|
||||
res=[self selectedDOMRange];
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
return res;
|
||||
}
|
||||
|
||||
- (void)updateSearch:(NSSearchField *)sender
|
||||
{
|
||||
NSString *searchString = [sender stringValue];
|
||||
DLog(@"searchString:%@",searchString);
|
||||
|
||||
DOMRange *selection;
|
||||
|
||||
if([searchString length]>0){
|
||||
selection=[self highlightAllOccurencesOfString:searchString];
|
||||
[[sender window] makeFirstResponder:sender];
|
||||
if(selection!=nil)
|
||||
[self setSelectedDOMRange:selection affinity:NSSelectionAffinityDownstream];
|
||||
}else{
|
||||
[self removeAllHighlights];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeAllHighlights:(DOMNode *)_node
|
||||
|
||||
Reference in New Issue
Block a user