From 6430230a7b9f3bdcded595265b35e94818b43aeb Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Wed, 10 Jun 2020 12:55:43 +0200 Subject: [PATCH 1/2] Fix onSubmitEditing firing on delete/tab `-[RCTBaseTextInputView textInputShouldReturn]` also sends a submit event. --- Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m b/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m index a8fe7f0a39445b..60975e7d7006b7 100644 --- a/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +++ b/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m @@ -353,7 +353,7 @@ - (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector BOOL commandHandled = NO; id textInputDelegate = [_backedTextInputView textInputDelegate]; // enter/return - if (textInputDelegate.textInputShouldReturn && (commandSelector == @selector(insertNewline:) || commandSelector == @selector(insertNewlineIgnoringFieldEditor:))) { + if ((commandSelector == @selector(insertNewline:) || commandSelector == @selector(insertNewlineIgnoringFieldEditor:)) && textInputDelegate.textInputShouldReturn) { [_backedTextInputView.window makeFirstResponder:nil]; commandHandled = YES; //backspace From 5deabb02480c952d21bd7dc89faf17af6f24e761 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Wed, 10 Jun 2020 14:08:01 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Submit=20only=20on=20=E2=8C=98+Enter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RCTBackedTextInputDelegateAdapter.m | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m b/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m index 60975e7d7006b7..69a793c2130353 100644 --- a/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +++ b/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m @@ -14,6 +14,13 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingContext; +#if TARGET_OS_OSX // [TODO(macOS ISS#2323203) +BOOL RCTEventIsCommandEnterEvent(NSEvent *event) { + NSEventModifierFlags modifierFlags = event.modifierFlags & NSEventModifierFlagDeviceIndependentFlagsMask; + return (modifierFlags & NSEventModifierFlagCommand) == NSEventModifierFlagCommand && event.keyCode == 0x24; +} +#endif // ]TODO(macOS ISS#2323203) + @interface RCTBackedTextFieldDelegateAdapter () #if !TARGET_OS_OSX // [TODO(macOS ISS#2323203) @@ -275,18 +282,16 @@ - (void)textViewDidEndEditing:(__unused UITextView *)textView - (BOOL)textView:(__unused UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { +#if !TARGET_OS_OSX // TODO(macOS ISS#2323203) // Custom implementation of `textInputShouldReturn` and `textInputDidReturn` pair for `UITextView`. if (!_backedTextInputView.textWasPasted && [text isEqualToString:@"\n"]) { if ([_backedTextInputView.textInputDelegate textInputShouldReturn]) { [_backedTextInputView.textInputDelegate textInputDidReturn]; -#if !TARGET_OS_OSX // TODO(macOS ISS#2323203) [_backedTextInputView endEditing:NO]; -#else // [TODO(macOS ISS#2323203) - [[_backedTextInputView window] endEditingFor:nil]; -#endif // ]TODO(macOS ISS#2323203) return NO; } } +#endif // ]TODO(macOS ISS#2323203) BOOL result = [_backedTextInputView.textInputDelegate textInputShouldChangeTextInRange:range replacementText:text]; if (result) { @@ -352,9 +357,11 @@ - (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector { BOOL commandHandled = NO; id textInputDelegate = [_backedTextInputView textInputDelegate]; - // enter/return - if ((commandSelector == @selector(insertNewline:) || commandSelector == @selector(insertNewlineIgnoringFieldEditor:)) && textInputDelegate.textInputShouldReturn) { - [_backedTextInputView.window makeFirstResponder:nil]; + // cmd + enter/return + if (commandSelector == @selector(noop:) && RCTEventIsCommandEnterEvent(NSApp.currentEvent)) { + if (textInputDelegate.textInputShouldReturn) { + [_backedTextInputView.window makeFirstResponder:nil]; + } commandHandled = YES; //backspace } else if (commandSelector == @selector(deleteBackward:)) {