Skip to content

Instantly share code, notes, and snippets.

@boucher
Created September 16, 2008 20:11
Show Gist options
  • Save boucher/11124 to your computer and use it in GitHub Desktop.
Save boucher/11124 to your computer and use it in GitHub Desktop.
diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j
index f1ba2d3..d3938d7 100644
--- a/AppKit/CPTextField.j
+++ b/AppKit/CPTextField.j
@@ -97,15 +97,17 @@ var _CPTextFieldSquareBezelColor = nil;
*/
@implementation CPTextField : CPControl
{
+ id _delegate;
+
BOOL _isBordered;
BOOL _isBezeled;
CPTextFieldBezelStyle _bezelStyle;
-
+
BOOL _isEditable;
BOOL _isSelectable;
-
+
id _value;
+ id _editingValue;
-
+
CPLineBreakMode _lineBreakMode;
#if PLATFORM(DOM)
DOMElement _DOMTextElement;
@@ -306,9 +308,23 @@ var _CPTextFieldSquareBezelColor = nil;
[self sendAction:[self action] to:[self target]];
[[self window] makeFirstResponder:nil];
- }
+ }
+ else
+ {
+ [self textMayHaveChanged];
+ }
};
+ element.onkeydown = function(aDOMEvent)
+ {
+ [self textMayHaveChanged];
+ }
+
+ element.onkeyup = function(aDOMEvent)
+ {
+ [self textMayHaveChanged];
+ }
+
+ _editingValue = "";
+
[[CPDOMWindowBridge sharedDOMWindowBridge] _propagateCurrentDOMEvent:YES];
#endif
@@ -322,11 +338,38 @@ var _CPTextFieldSquareBezelColor = nil;
_DOMElement.removeChild(element);
[self setStringValue:element.value];
+
+ element.onkeydown = nil;
+ element.onkeypress = nil;
+ element.onkeyup = nil;
#endif
return YES;
}
+- (void)textMayHaveChanged
+{
+ var element = [[self class] _inputElement];
+
+ if(element.value != _editingValue)
+ {
+ _editingValue = element.value;
+
+ if ([_delegate respondsToSelector:@selector(textDidChange:)])
+ [_delegate textDidChange:self];
+ }
+}
+
+- (void)setDelegate:(id)delegate
+{
+ _delegate = delegate;
+}
+
+- (id)delegate
+{
+ return _delegate;
+}
+
- (void)setEditable:(BOOL)shouldBeEditable
{
_isEditable = shouldBeEditable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment