From d52b19a69ea910d948baf54358d243aa7ce38a1b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 1 Nov 2017 11:28:58 -0400 Subject: [PATCH 1/2] Let users with external keyboards send messages using modifier-return (shift, command, option). // FREEBIE --- .../ConversationInputTextView.h | 2 + .../ConversationInputTextView.m | 42 +++++++++++++++++++ .../ConversationViewController.m | 5 +++ 3 files changed, 49 insertions(+) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.h b/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.h index ef685c361..92e9f8b2c 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.h @@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)inputTextViewDidBecomeFirstResponder; +- (void)inputTextViewSendMessagePressed; + @end #pragma mark - diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m b/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m index c1f1d3b79..3dc426691 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m @@ -196,6 +196,48 @@ NS_ASSUME_NONNULL_BEGIN [textView resignFirstResponder]; } +#pragma mark - Key Commands + +- (nullable NSArray *)keyCommands +{ + // We're permissive about what modifier key we accept for the "send message" hotkey. + // We accept command-return, option-return and shift-return. We don't support + // control-return because it doesn't work. + return @[ + [UIKeyCommand keyCommandWithInput:@"\r" + modifierFlags:UIKeyModifierShift + action:@selector(modifiedReturnPressed:) + discoverabilityTitle:@"Send Message"], + [UIKeyCommand keyCommandWithInput:@"\r" + modifierFlags:UIKeyModifierCommand + action:@selector(modifiedReturnPressed:) + discoverabilityTitle:@"Send Message"], + // "Alternate" is option. + [UIKeyCommand keyCommandWithInput:@"\r" + modifierFlags:UIKeyModifierAlternate + action:@selector(modifiedReturnPressed:) + discoverabilityTitle:@"Send Message"], + ]; +} + +- (void)modifiedReturnPressed:(UIKeyCommand *)sender +{ + DDLogInfo(@"%@ modifiedReturnPressed: %@", self.logTag, sender.input); + [self.inputTextViewDelegate inputTextViewSendMessagePressed]; +} + +#pragma mark - Logging + ++ (NSString *)logTag +{ + return [NSString stringWithFormat:@"[%@]", self.class]; +} + +- (NSString *)logTag +{ + return self.class.logTag; +} + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index f54696adc..47f17eedd 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3443,6 +3443,11 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { [self scrollToBottomAnimated:YES]; } +- (void)inputTextViewSendMessagePressed +{ + [self sendButtonPressed]; +} + - (void)didPasteAttachment:(SignalAttachment *_Nullable)attachment { DDLogError(@"%@ %s", self.tag, __PRETTY_FUNCTION__); From 5d4316755fa9bf21a77ecf6044ab22af80926fad Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 1 Nov 2017 12:48:07 -0400 Subject: [PATCH 2/2] Respond to CR. // FREEBIE --- .../ConversationView/ConversationInputTextView.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m b/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m index 3dc426691..c41f7c542 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m @@ -201,13 +201,13 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSArray *)keyCommands { // We're permissive about what modifier key we accept for the "send message" hotkey. - // We accept command-return, option-return and shift-return. We don't support - // control-return because it doesn't work. + // We accept command-return, option-return. + // + // We don't support control-return because it doesn't work. + // + // We don't support shift-return because it is often used for "newline" in other + // messaging apps. return @[ - [UIKeyCommand keyCommandWithInput:@"\r" - modifierFlags:UIKeyModifierShift - action:@selector(modifiedReturnPressed:) - discoverabilityTitle:@"Send Message"], [UIKeyCommand keyCommandWithInput:@"\r" modifierFlags:UIKeyModifierCommand action:@selector(modifiedReturnPressed:)