diff --git a/KSPasswordField.h b/KSPasswordField.h index b56d0b5..e04e904 100644 --- a/KSPasswordField.h +++ b/KSPasswordField.h @@ -56,6 +56,7 @@ typedef NS_ENUM(NSInteger, PasswordMeter) { @property(nonatomic) BOOL showStrength; @property(nonatomic) BOOL showMatchIndicator; +@property (nonatomic) IBInspectable BOOL cleanUpWhitespace; @property(nonatomic) PasswordMeter passwordMeter; /** diff --git a/KSPasswordField.m b/KSPasswordField.m index 3b49b85..860665c 100644 --- a/KSPasswordField.m +++ b/KSPasswordField.m @@ -327,6 +327,7 @@ - (id)initWithFrame:(NSRect)frameRect; if (self = [super initWithFrame:frameRect]) { _becomesFirstResponderWhenToggled = YES; + _cleanUpWhitespace = YES; // Don't show text by default. This needs to be called to replace the standard cell with our custom one. [self setShowsText:NO]; @@ -339,6 +340,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder; if (self = [super initWithCoder:aDecoder]) { _becomesFirstResponderWhenToggled = YES; + _cleanUpWhitespace = YES; // Don't show text by default. This needs to be called to replace the standard cell with our custom one. [self setShowsText:NO]; @@ -514,7 +516,8 @@ - (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affecte { BOOL shouldChange = YES; BOOL changingEntireContents = (affectedCharRange.location == 0) && (affectedCharRange.length == [textView.string length]); - if (changingEntireContents) + + if (changingEntireContents && self.cleanUpWhitespace) { // we check for text containing non-whitespace characters but starting with or ending with whitespace // if we find it, we assume that it's being pasted in, and we trim the whitespace off first