diff options
Diffstat (limited to 'Source/SPDataCellFormatter.m')
-rw-r--r-- | Source/SPDataCellFormatter.m | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Source/SPDataCellFormatter.m b/Source/SPDataCellFormatter.m index 4f005c23..ae03a441 100644 --- a/Source/SPDataCellFormatter.m +++ b/Source/SPDataCellFormatter.m @@ -40,6 +40,8 @@ } #endif + + - (NSString *)stringForObjectValue:(id)anObject { @@ -72,16 +74,25 @@ - (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error { - // No limit set + // No limit set if (textLimit == 0) return YES; + // A single character over the length of the string - likely typed. Prevent the change. + if ([partialString length] == textLimit + 1) { + NSBeep(); + return NO; + } + + // If the string is considerably longer than the limit, likely pasted. Accept but truncate. if ([partialString length] > textLimit) { NSBeep(); - newString = [NSString stringWithCharacters:partialString length:textLimit]; + *newString = [NSString stringWithString:[partialString substringToIndex:textLimit]]; + return NO; } - return ([partialString length] <= textLimit); + // Length inside limit. + return YES; } @end |