Skip to content

Commit

Permalink
Guard call to control flow plugin with respondsToSelector (#217)
Browse files Browse the repository at this point in the history
Guard call to control flow plugin with respondsToSelector

Also did audit of all other enableMentionsPluginV2 calls outside of the plugin itself. not needed anywhere else
  • Loading branch information
bkoatz authored Nov 13, 2020
1 parent 015bd5f commit f5b6dc0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Hakawai/Core/HKWTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ - (void)cut:(id)sender {
}

- (void)paste:(id)sender {
if (enableMentionsPluginV2 && [self.copyString length] > 0) {
BOOL implementsWillPasteTextInRange = [self.controlFlowPlugin respondsToSelector:@selector(textView:willPasteTextInRange:isProgrammatic:)];
if (enableMentionsPluginV2 && [self.copyString length] > 0 && implementsWillPasteTextInRange) {
__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;
Expand All @@ -215,7 +216,9 @@ - (void)paste:(id)sender {
// Inform delegate that text view has changed since we are overriding the normal paste behavior that would do so automatically
[self.delegate textViewDidChange:self];
} else {
[self.controlFlowPlugin textView:self willPasteTextInRange:self.selectedRange isProgrammatic:NO];
if (implementsWillPasteTextInRange) {
[self.controlFlowPlugin textView:self willPasteTextInRange:self.selectedRange isProgrammatic:NO];
}
[super paste:sender];
}
self.wasPaste = YES;
Expand Down

0 comments on commit f5b6dc0

Please sign in to comment.