From 8f7e06f9d6424d7643eb3e7b17f42bc3d1272884 Mon Sep 17 00:00:00 2001 From: Mike Fellows Date: Fri, 15 Jul 2011 18:53:08 -0700 Subject: [PATCH] Fix regression to CPTextField's insertNewline, duplicate target actions were being called when an edit on a textfield was ended with an enter/return keypress --- AppKit/CPTextField.j | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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]; } }