From 07966bb7fedfdf7a0503d98feb8bf98f6514fbb1 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Wed, 16 Nov 2011 12:22:22 +0000 Subject: [PATCH] Fixed with CPTokenField: crash if added to a window in a unit test. --- AppKit/CPTokenField.j | 8 +++++--- Tests/AppKit/CPTokenFieldTest.j | 13 ++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/AppKit/CPTokenField.j b/AppKit/CPTokenField.j index abf0081bc..6ad18c2f2 100755 --- a/AppKit/CPTokenField.j +++ b/AppKit/CPTokenField.j @@ -184,7 +184,8 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", token = [self _inputElement].value; // Make sure the user typed an actual token to prevent the previous token from being emptied - // If the input area is empty, we want to fallback to the normal behavior, resigning first responder or select the next or previous key view + // If the input area is empty, we want to fallback to the normal behavior, resigning first + // responder or selecting the next or previous key view. if (!token || token === @"") { if (DOMEvent && DOMEvent.keyCode === CPTabKeyCode) @@ -199,7 +200,6 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", return; } - var objectValue = [self objectValue]; // Remove the uncompleted token and add the token string. @@ -608,14 +608,16 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", { } - // ======== // = VIEW = // ======== - (void)viewDidMoveToWindow { [[[self window] contentView] addSubview:_autocompleteContainer]; + +#if PLATFORM(DOM) _autocompleteContainer._DOMElement.style.zIndex = 1000; // Anything else doesn't seem to work +#endif } - (void)removeFromSuperview diff --git a/Tests/AppKit/CPTokenFieldTest.j b/Tests/AppKit/CPTokenFieldTest.j index 1cbc071e0..14e5440f7 100644 --- a/Tests/AppKit/CPTokenFieldTest.j +++ b/Tests/AppKit/CPTokenFieldTest.j @@ -1,5 +1,7 @@ @import +[CPApplication sharedApplication]; + @implementation CPTokenFieldTest : OJTestCase { } @@ -17,4 +19,13 @@ [self assert:[unarchived tokenizingCharacterSet] equals:[CPCharacterSet characterSetWithCharactersInString:@","]]; } -@end \ No newline at end of file +- (void)testCreate +{ + var aWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0) styleMask:CPWindowNotSizable], + tokenField = [[CPTokenField alloc] initWithFrame:CGRectMake(10, 10, 100, 28)]; + + // This shouldn't crash. + [[aWindow contentView] addSubview:tokenField]; +} + +@end