Skip to content

Commit

Permalink
Eliminate flashing of insertion point when becoming first responder d…
Browse files Browse the repository at this point in the history
…ue to double setTimeout
  • Loading branch information
aparajita committed Apr 9, 2012
1 parent bc8dc10 commit 9164208
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions AppKit/CPTextField.j
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");

// Select the text if the textfield became first responder through keyboard interaction
if (!_willBecomeFirstResponderByClick)
[self selectText:self];
[self _selectText:self immediately:YES];

_willBecomeFirstResponderByClick = NO;

Expand Down Expand Up @@ -1071,24 +1071,36 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
*/
- (void)selectText:(id)sender
{
// FIXME Should this really make the text field the first responder?
[self _selectText:sender immediately:NO];
}

- (void)_selectText:(id)sender immediately:(BOOL)immediately
{
// Selecting the text in a field makes it the first responder
if (([self isEditable] || [self isSelectable]))
{
var wind = [self window];

#if PLATFORM(DOM)
var element = [self _inputElement];

if ([[self window] firstResponder] === self)
window.setTimeout(function() { element.select(); }, 0);
else if ([self window] !== nil && [[self window] makeFirstResponder:self])
window.setTimeout(function() {[self selectText:sender];}, 0);
if ([wind firstResponder] === self)
{
if (immediately)
element.select();
else
window.setTimeout(function() { element.select(); }, 0);
}
else if (wind !== nil && [wind makeFirstResponder:self])
[self _selectText:sender immediately:immediately];
#else
// Even if we can't actually select the text we need to preserve the first
// responder side effect.
if ([self window] !== nil && [[self window] firstResponder] !== self)
[[self window] makeFirstResponder:self];
if (wind !== nil && [wind firstResponder] !== self)
[wind makeFirstResponder:self];
#endif
}

}

- (void)copy:(id)sender
Expand Down

0 comments on commit 9164208

Please sign in to comment.