Created
November 4, 2010 01:11
-
-
Save fpotter/661987 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation PITextField : CPTextField | |
- (void)textDidFocus:(CPNotification)note | |
{ | |
[self _inputElement].onpaste = function(e, elName) | |
{ | |
var originalString = [self stringValue]; | |
[self deleteBackward:self]; | |
var selectedRange = [self selectedRange], | |
stringValue = [self stringValue], | |
pasteString = e.clipboardData.getData("Text"), | |
newValue = [stringValue stringByReplacingCharactersInRange:selectedRange withString:pasteString]; | |
[self setStringValue:newValue]; | |
[self setSelectedRange:CPMakeRange(selectedRange.location+pasteString.length, 0)]; | |
var modifiedString = [self stringValue]; | |
if (originalString !== modifiedString) | |
{ | |
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]]; | |
} | |
// If we don't do this, we get hit twice for some reason. | |
e.preventDefault(); | |
}; | |
} | |
- (void)textDidBlur:(CPNotification)note | |
{ | |
[self _inputElement].onpaste = null; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment