Compare commits

...
7 Commits
5 changed files with 34 additions and 14 deletions
+16 -8
View File
@@ -97,7 +97,6 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
{
if (self = [super initWithFrame:frame])
{
_selectedRange = CPMakeRange(0, 0);
_completionDelay = [CPTokenField defaultCompletionDelay];
_tokenizingCharacterSet = [[self class] defaultTokenizingCharacterSet];
[self setBezeled:YES];
@@ -114,6 +113,8 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
- (void)_init
{
_selectedRange = CPMakeRange(0, 0);
var frame = [self frame];
_tokenScrollView = [[CPScrollView alloc] initWithFrame:CGRectMakeZero()];
@@ -171,19 +172,20 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
- (void)_autocompleteWithDOMEvent:(JSObject)DOMEvent
{
if (!_cachedCompletions || ![self hasThemeState:CPThemeStateAutoCompleting])
if (![self _inputElement].value && (!_cachedCompletions || ![self hasThemeState:CPThemeStateAutoCompleting]))
return;
[self _hideCompletions];
var token = _cachedCompletions[[_autocompleteView selectedRow]],
var token = _cachedCompletions ? _cachedCompletions[[_autocompleteView selectedRow]] : nil,
shouldRemoveLastObject = token !== @"" && [self _inputElement].value !== @"";
if (!token)
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 fall back to the normal behavior, resigning first
// responder or selecting the next or previous key view.
if (!token || token === @"")
{
if (DOMEvent && DOMEvent.keyCode === CPTabKeyCode)
@@ -198,7 +200,6 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
return;
}
var objectValue = [self objectValue];
// Remove the uncompleted token and add the token string.
@@ -269,8 +270,13 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
var indexOfToken = [[self _tokens] indexOfObject:token],
objectValue = [self objectValue];
// If the token was selected, deselect it for selection preservation.
[self _deselectToken:token];
// If the selection was to the right of the deleted token, move it to the left. If the deleted token was
// selected, deselect it.
if (indexOfToken < _selectedRange.location)
_selectedRange.location--;
else
[self _deselectToken:token];
// Preserve selection.
var selection = CPCopyRange(_selectedRange);
[objectValue removeObjectAtIndex:indexOfToken];
@@ -602,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
+4 -3
View File
@@ -108,7 +108,7 @@ function CGColorCreateCopy(aColor)
*/
function CGColorCreateGenericGray(gray, alpha)
{
return CGColorCreate(CGColorSpaceCreateDeviceRGB(), [gray,gray,gray, alpha]);
return CGColorCreate(CGColorSpaceCreateDeviceRGB(), [gray, gray, gray, alpha]);
}
/*!
@@ -137,7 +137,7 @@ function CGColorCreateGenericRGB(red, green, blue, alpha)
*/
function CGColorCreateGenericCMYK(cyan, magenta, yellow, black, alpha)
{
return CGColorCreate(CGColorSpaceCreateDeviceCMYK(),
return CGColorCreate(CGColorSpaceCreateDeviceCMYK(),
[cyan, magenta, yellow, black, alpha]);
}
@@ -150,7 +150,8 @@ function CGColorCreateGenericCMYK(cyan, magenta, yellow, black, alpha)
*/
function CGColorCreateCopyWithAlpha(aColor, anAlpha)
{
if ( !aColor ) return aColor; // Avoid error null pointer in next line
if (!aColor)
return aColor; // Avoid error null pointer in next line
var components = aColor.components.slice();
+12 -1
View File
@@ -1,5 +1,7 @@
@import <AppKit/CPTokenField.j>
[CPApplication sharedApplication];
@implementation CPTokenFieldTest : OJTestCase
{
}
@@ -17,4 +19,13 @@
[self assert:[unarchived tokenizingCharacterSet] equals:[CPCharacterSet characterSetWithCharactersInString:@","]];
}
@end
- (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
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -31,7 +31,7 @@ PROJECT_NAME = " API"
# This could be handy for archiving the generated documentation or
# if some version control system is used.
PROJECT_NUMBER = 0.9.1
PROJECT_NUMBER = 0.9.5
PROJECT_LOGO = ./Tools/Documentation/logo.png