Permalink
Browse files

Let the file view search field grab focus only when it is required.

  • Loading branch information...
1 parent 21b8f38 commit 754afba8c427ccb11908af75f82e2f32a05a6da2 @jphalip committed May 31, 2012
Showing with 17 additions and 12 deletions.
  1. +4 −4 GLFileView.m
  2. +1 −1 SearchWebView.h
  3. +12 −7 SearchWebView.m
View
@@ -703,7 +703,7 @@ - (NSString *)numberOfMatchesString
- (void) updateSearch
{
- [view search:searchField update:YES direction:YES];
+ [view search:searchField update:YES grabFocus:NO direction:YES];
[self updateSearchUI];
}
@@ -725,7 +725,7 @@ - (IBAction)searchFieldChanged:(id)sender
{
BOOL update=[[searchField stringValue] isEqualToString:searchString]? NO: YES;
searchString=[searchField stringValue];
- [view search:searchField update:update direction:YES];
+ [view search:searchField update:update grabFocus:YES direction:YES];
[self updateSearchUI];
}
@@ -734,9 +734,9 @@ - (IBAction)stepperPressed:(id)sender {
NSInteger selectedSegment = [sender selectedSegment];
if (selectedSegment == 0)
- [view search:searchField update:NO direction:NO];
+ [view search:searchField update:NO grabFocus:YES direction:NO];
else
- [view search:searchField update:NO direction:YES];
+ [view search:searchField update:NO grabFocus:YES direction:YES];
}
@end
View
@@ -16,6 +16,6 @@
- (void)highlightAllOccurencesOfString:(NSString*)str direction:(BOOL)forward;
- (void)highlightAllOccurencesOfString:(NSString*)str inNode:(DOMNode *)node;
- (void)removeAllHighlights;
-- (void)search:(NSSearchField *)sender update:(BOOL)update direction:(BOOL)forward;
+- (void)search:(NSSearchField *)sender update:(BOOL)update grabFocus:(BOOL)grabFocus direction:(BOOL)forward;
@end
View
@@ -68,21 +68,26 @@ - (void)highlightAllOccurencesOfString:(NSString*)str update:(BOOL)update direct
}
}
-- (void)search:(NSSearchField *)sender update:(BOOL)update direction:(BOOL)forward
+- (void)search:(NSSearchField *)sender update:(BOOL)update grabFocus:(BOOL)grabFocus direction:(BOOL)forward
{
NSString *searchString = [sender stringValue];
DLog(@"searchString:%@",searchString);
-
- // Back-up the search field's caret position so we can restore it later
- NSRange searchFieldSelectedRange = [[sender currentEditor] selectedRange];
+
+ NSRange searchFieldSelectedRange;
+ if (grabFocus) {
+ // Back-up the search field's caret position so we can restore it later
+ searchFieldSelectedRange = [[sender currentEditor] selectedRange];
+ }
if([searchString length]>0){
[self highlightAllOccurencesOfString:searchString update:update direction:forward];
- // Bring the search field back in focus and restore its caret position
- [[sender window] makeFirstResponder:sender];
- [[sender currentEditor] setSelectedRange:searchFieldSelectedRange];
+ if (grabFocus) {
+ // Bring the search field back in focus and restore its caret position
+ [[sender window] makeFirstResponder:sender];
+ [[sender currentEditor] setSelectedRange:searchFieldSelectedRange];
+ }
if(result!=nil) {
[self setSelectedDOMRange:result affinity:NSSelectionAffinityDownstream];

0 comments on commit 754afba

Please sign in to comment.