summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-29 17:43:54 -0400
committerPietro Gagliardi <[email protected]>2014-08-29 17:43:54 -0400
commit54efcdc5d6819d65c6ba9affb1e31482ee608bd7 (patch)
tree8d406fb288d2676476743ac5cf4698802e21008f
parenta4574d582868d3e9f9c7a0dbe1545c190f30ebaf (diff)
Fixed Mac OS X Area.OpenTextFieldAt() not behaving properly. The behavior is still a little weird now, but permissible.
-rw-r--r--redo/area.go2
-rw-r--r--redo/area_darwin.m7
2 files changed, 5 insertions, 4 deletions
diff --git a/redo/area.go b/redo/area.go
index 1c2141f..9849ef5 100644
--- a/redo/area.go
+++ b/redo/area.go
@@ -49,7 +49,7 @@ type Area interface {
// It panics if the coordinates fall outside the Area.
// Any text previously in the TextField (be it by the user or by a call to SetTextFieldText()) is retained.
// The TextField receives the input focus so the user can type things; when the TextField loses the input focus, it hides itself and signals the event set by OnTextFieldDismissed.
- // TODO escape key
+ // The TextField will also dismiss itself on some platforms when the user "completes editing"; the exact meaning of this is platform-specific.
OpenTextFieldAt(x int, y int)
// TextFieldText and TextFieldSetText get and set the OpenTextFieldAt TextField's text, respectively.
diff --git a/redo/area_darwin.m b/redo/area_darwin.m
index 020ece8..f9401c8 100644
--- a/redo/area_darwin.m
+++ b/redo/area_darwin.m
@@ -6,6 +6,7 @@
#define toNSEvent(x) ((NSEvent *) (x))
#define toNSView(x) ((NSView *) (x))
+#define toNSObject(x) ((NSObject *) (x))
#define toNSTextField(x) ((NSTextField *) (x))
#define toNSInteger(x) ((NSInteger) (x))
@@ -100,10 +101,10 @@ retevent(doKeyDown, areaView_keyDown)
retevent(doKeyUp, areaView_keyUp)
retevent(doFlagsChanged, areaView_flagsChanged)
-- (BOOL)control:(NSControl *)c textShouldEndEditing:(NSText *)t
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
areaTextFieldDismissed(self->goarea);
- return YES;
+ [toNSObject(object) removeObserver:self forKeyPath:@"firstResponder"];
}
@end
@@ -216,7 +217,6 @@ void areaSetTextField(id area, id textfield)
goAreaView *a = (goAreaView *) area;
NSTextField *tf = toNSTextField(textfield);
- [tf setDelegate:a];
[a addSubview:tf];
}
@@ -231,4 +231,5 @@ void areaTextFieldOpen(id area, id textfield, intptr_t x, intptr_t y)
[tf setFrameOrigin:NSMakePoint((CGFloat) x, (CGFloat) y)];
[tf setHidden:NO];
[[tf window] makeFirstResponder:tf];
+ [[tf window] addObserver:a forKeyPath:@"firstResponder" options:NSKeyValueObservingOptionNew context:NULL];
}