Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84019b9

Browse files
author
ignacio
committed
Identifies which alert view was shown, before proceeding to clear the text input's content. Fixes slackhq#196
1 parent f880a32 commit 84019b9

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

Source/Classes/SLKTextViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,7 @@ NS_CLASS_AVAILABLE_IOS(7_0) @interface SLKTextViewController : UIViewController
462462
/** UIGestureRecognizerDelegate */
463463
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer NS_REQUIRES_SUPER;
464464

465+
/** UIAlertViewDelegate */
466+
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex NS_REQUIRES_SUPER;
467+
465468
@end

Source/Classes/SLKTextViewController.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
NSString * const SLKKeyboardWillHideNotification = @"SLKKeyboardWillHideNotification";
2525
NSString * const SLKKeyboardDidHideNotification = @"SLKKeyboardDidHideNotification";
2626

27+
NSInteger const SLKAlertViewClearTextTag = 1534347677; // absolute hash of 'SLKTextViewController' string
28+
2729
@interface SLKTextViewController ()
2830
{
2931
CGPoint _scrollViewOffsetBeforeDragging;
@@ -866,6 +868,7 @@ - (void)willRequestUndo
866868
[alert addButtonWithTitle:NSLocalizedString(@"Undo", nil)];
867869
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", nil)];
868870
[alert setCancelButtonIndex:1];
871+
[alert setTag:SLKAlertViewClearTextTag];
869872
[alert setDelegate:self];
870873
[alert show];
871874
}
@@ -1816,9 +1819,8 @@ - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gesture
18161819

18171820
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
18181821
{
1819-
if (self.shakeToClearEnabled && buttonIndex != [alertView cancelButtonIndex] ) {
1820-
1821-
// Clears the text and but not the undo manager
1822+
if (alertView.tag == SLKAlertViewClearTextTag && self.shakeToClearEnabled && buttonIndex != [alertView cancelButtonIndex] ) {
1823+
// Clears the text but doesn't clear the undo manager
18221824
[self.textView slk_clearText:NO];
18231825
}
18241826
}

0 commit comments

Comments
 (0)