diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index e7831c138..2dbfcd81a 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -779,14 +779,21 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); { if ([self _valueIsValid:_stringValue]) { + // If _isEditing == YES then the target action can also be called via + // resignFirstResponder, and it is possible that the target action + // itself will change this textfield's responder status, so start by + // setting the _isEditing flag to NO to prevent the target action being + // called twice (once below and once from resignFirstResponder). + if (_isEditing) + { + _isEditing = NO; + [self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:nil]]; + } + + // If there is no target action, or the sendAction call returns + // success. if (![self action] || [self sendAction:[self action] to:[self target]]) { - if (_isEditing) - { - _isEditing = NO; - [self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:nil]]; - } - [self selectAll:nil]; } }