From e686b70de339fdb47b5d96e59e8b6df728d36d74 Mon Sep 17 00:00:00 2001 From: Binya Koatz Date: Thu, 5 Nov 2020 12:51:01 -0800 Subject: [PATCH] Fix compiler warnings + small fix for selection (#209) Fix compiler warnings + small fix for selection --- Hakawai/Core/HKWTextView.m | 3 ++- Hakawai/Mentions/HKWMentionsPluginV1.m | 12 ++++++++---- Hakawai/Mentions/HKWMentionsPluginV2.m | 7 +++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Hakawai/Core/HKWTextView.m b/Hakawai/Core/HKWTextView.m index cc242fc..4644b31 100644 --- a/Hakawai/Core/HKWTextView.m +++ b/Hakawai/Core/HKWTextView.m @@ -202,13 +202,14 @@ - (void)cut:(id)sender { - (void)paste:(id)sender { if (enableMentionsPluginV2 && [self.copyString length] > 0) { + __strong __auto_type copyString = self.copyString; // In order to maintain mentions styling, insert the saved copyString into the attributed text NSUInteger cursorLocationAfterPaste = self.selectedRange.location+self.copyString.length; NSRange selectionRangeBeforePaste = self.selectedRange; // Let control plugin know that text will be pasted, so it can remove any existing mentions attributes at that point [self.controlFlowPlugin textView:self willPasteTextInRange:self.selectedRange]; NSMutableAttributedString *string = [self.attributedText mutableCopy]; - [string replaceCharactersInRange:selectionRangeBeforePaste withAttributedString:self.copyString]; + [string replaceCharactersInRange:selectionRangeBeforePaste withAttributedString:copyString]; [self setAttributedText:string]; self.selectedRange = NSMakeRange(cursorLocationAfterPaste, 0); } else { diff --git a/Hakawai/Mentions/HKWMentionsPluginV1.m b/Hakawai/Mentions/HKWMentionsPluginV1.m index 2379b3b..9221d48 100644 --- a/Hakawai/Mentions/HKWMentionsPluginV1.m +++ b/Hakawai/Mentions/HKWMentionsPluginV1.m @@ -2088,13 +2088,13 @@ - (void)setState:(HKWMentionsState)state { if ([strongStateChangeDelegate respondsToSelector:@selector(mentionsPlugin:stateChangedTo:from:)]) { if (state == HKWMentionsStartDetectionStateCreatingMention && _state != HKWMentionsStartDetectionStateCreatingMention) { [strongStateChangeDelegate mentionsPlugin:self - stateChangedTo:HKWMentionsPluginStateCreatingMention - from:HKWMentionsPluginStateQuiescent]; + stateChangedTo:HKWMentionsPluginStateCreatingMention + from:HKWMentionsPluginStateQuiescent]; } else if (state != HKWMentionsStartDetectionStateCreatingMention && _state == HKWMentionsStartDetectionStateCreatingMention) { [strongStateChangeDelegate mentionsPlugin:self - stateChangedTo:HKWMentionsPluginStateQuiescent - from:HKWMentionsPluginStateCreatingMention]; + stateChangedTo:HKWMentionsPluginStateQuiescent + from:HKWMentionsPluginStateCreatingMention]; } } @@ -2208,6 +2208,10 @@ - (unichar)getExplicitSearchControlCharacter { return self.creationStateMachine.explicitSearchControlCharacter; } +- (void)textView:(__unused UITextView *)textView willPasteTextInRange:(__unused NSRange)range { + return; +} + #pragma mark - Developer NSString * _Nonnull nameForMentionsState(HKWMentionsState s) { diff --git a/Hakawai/Mentions/HKWMentionsPluginV2.m b/Hakawai/Mentions/HKWMentionsPluginV2.m index ea46370..4d9c85c 100644 --- a/Hakawai/Mentions/HKWMentionsPluginV2.m +++ b/Hakawai/Mentions/HKWMentionsPluginV2.m @@ -968,7 +968,7 @@ - (void)highlightMentionIfNeededForCursorLocation:(NSUInteger)cursorLocation { // TODO: Remove text view from call // JIRA: POST-14031 -- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { +- (BOOL)textView:(__unused UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { BOOL returnValue = YES; // In simple refactor, we only focus on insertions and deletions in order to allow for personalization/deletions/bleaching of mentions @@ -1029,6 +1029,9 @@ - (void)bleachMentionsIntersectingWithRange:(NSRange)range { - (void)textViewDidChangeSelection:(UITextView *)textView { NSRange range = textView.selectedRange; if (range.length > 0) { + // If there is a multicharacter range, we unselect any mentions currently selected + [self toggleMentionsFormattingIfNeededAtRange:self.currentlySelectedMentionRange selected:NO]; + self.currentlySelectedMentionRange = NSMakeRange(NSNotFound, 0); return; } @@ -1058,7 +1061,7 @@ - (void)handleMentionsCreationInText:(NSString *)text atLocation:(NSUInteger)loc } } -- (void)textView:(UITextView *)textView willPasteTextInRange:(NSRange)range { +- (void)textView:(__unused UITextView *)textView willPasteTextInRange:(NSRange)range { if (self.currentlySelectedMentionRange.location != NSNotFound) { [self bleachExistingMentionAtRange:self.currentlySelectedMentionRange]; self.currentlySelectedMentionRange = NSMakeRange(NSNotFound, 0);