Created
March 11, 2009 09:55
-
-
Save angerman/77392 to your computer and use it in GitHub Desktop.
fixing the event queue for the CPTextField
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
diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j | |
index 40ac8c5..d83c0e0 100644 | |
--- a/AppKit/CPTextField.j | |
+++ b/AppKit/CPTextField.j | |
@@ -129,6 +129,7 @@ var _CPTextFieldSquareBezelColor = nil, | |
if (!CPTextFieldDOMInputElement) | |
{ | |
CPTextFieldDOMInputElement = document.createElement("input"); | |
+ CPTextFieldDOMInputElement.isActive = NO; | |
CPTextFieldDOMInputElement.style.position = "absolute"; | |
CPTextFieldDOMInputElement.style.top = "0px"; | |
CPTextFieldDOMInputElement.style.left = "0px"; | |
@@ -394,13 +395,21 @@ var _CPTextFieldSquareBezelColor = nil, | |
/* @ignore */ | |
- (BOOL)becomeFirstResponder | |
-{ | |
+{ | |
+ if(console) { | |
+ console.log("become first responder"); | |
+ console.log(self); | |
+ } | |
#if PLATFORM(DOM) | |
+ var element = [[self class] _inputElement]; | |
+ if(element.isActive) | |
+ return [[self window] makeFirstResponder:self]; | |
+ | |
var string = [self stringValue]; | |
[self setStringValue:""]; | |
- var element = [[self class] _inputElement]; | |
+ element.isActive = YES; | |
element.value = string; | |
element.style.color = _DOMElement.style.color; | |
@@ -430,6 +439,7 @@ var _CPTextFieldSquareBezelColor = nil, | |
{ | |
[self setObjectValue:element.value]; | |
[self sendAction:[self action] to:[self target]]; | |
+ this.isActive = NO; | |
[[self window] makeFirstResponder:nil]; | |
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; | |
}; | |
@@ -496,6 +506,17 @@ var _CPTextFieldSquareBezelColor = nil, | |
#if PLATFORM(DOM) | |
var element = [[self class] _inputElement]; | |
+ // if the current element is still active, force blur it! | |
+ if(element.isActive) { | |
+ element.blur(); | |
+ return YES; // maybe NO? | |
+ } | |
+ | |
+ if(console) { | |
+ console.log("resign first responder"); | |
+ console.log(self); | |
+ } | |
+ | |
//nil out dom handlers | |
element.onkeyup = nil; | |
element.onkeydown = nil; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment