Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it possible to disable whitespace cleanup #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions KSPasswordField.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
5 changes: 4 additions & 1 deletion KSPasswordField.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand Down Expand Up @@ -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
Expand Down