Skip to content

Commit

Permalink
Fix compiler warnings + small fix for selection (#209)
Browse files Browse the repository at this point in the history
Fix compiler warnings + small fix for selection
  • Loading branch information
bkoatz authored Nov 5, 2020
1 parent 2c1eab0 commit e686b70
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Hakawai/Core/HKWTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 8 additions & 4 deletions Hakawai/Mentions/HKWMentionsPluginV1.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions Hakawai/Mentions/HKWMentionsPluginV2.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e686b70

Please sign in to comment.