From fa3df4453556e10d4f4374981e8706aa34073b48 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Fri, 31 Dec 2010 14:49:03 -0300 Subject: [PATCH] Fixed: the text field selectText: message worked significantly differently in unit tests than in the browser. The message normally makes the text field the first responder, but this did not happen outside of the DOM platform. Also documented the first responder side effect. --- AppKit/CPTextField.j | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index d5609f26b..fc11d50f8 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -881,21 +881,28 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); } /*! - Select all the text in the CPTextField. + Make the receiver the first responder and select all the text in the field. */ - (void)selectText:(id)sender { -#if PLATFORM(DOM) - var element = [self _inputElement]; + // FIXME Should this really make the text field the first responder? if (([self isEditable] || [self isSelectable])) { +#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); - } +#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]; #endif + } } - (void)copy:(id)sender