Select tokens by clicking on them. Select multiple tokens by holding down shift. Also fixed a bug when deleting multiple tokens at a time.

This commit is contained in:
Alexander Ljungberg committed 2010-10-23 13:49:36 -03:00
1 parent d68f4359ac
commit 07330a0ca8
1 file changed
+30 -3
+30 -3
View File
@@ -72,6 +72,8 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
CPArray _cachedCompletions;
CPCharacterSet _tokenizingCharacterSet @accessors(property=tokenizingCharacterSet);
CPEvent _mouseDownEvent;
}
+ (CPCharacterSet)defaultTokenizingCharacterSet
@@ -263,7 +265,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
{
var tokens = [self objectValue];
for (var i = 0; i < _selectedRange.length; i++)
for (var i = _selectedRange.length - 1; i >= 0; i--)
[tokens removeObjectAtIndex:_selectedRange.location + i];
var collapsedSelection = _selectedRange.location;
@@ -391,12 +393,32 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
- (void)mouseDown:(CPEvent)anEvent
{
_mouseDownEvent = anEvent;
[self _selectToken:nil byExtendingSelection:NO];
// CPTokenFieldFocusInput = YES;
[super mouseDown:anEvent];
}
- (void)mouseUp:(CPEvent)anEvent
{
_mouseDownEvent = nil;
}
- (void)mouseDownOnToken:(_CPTokenFieldToken)aToken withEvent:(CPEvent)anEvent
{
_mouseDownEvent = anEvent;
}
- (void)mouseUpOnToken:(_CPTokenFieldToken)aToken withEvent:(CPEvent)anEvent
{
if (_mouseDownEvent && CGPointEqualToPoint([_mouseDownEvent locationInWindow], [anEvent locationInWindow]))
{
[[self window] makeFirstResponder:self];
[self _selectToken:aToken byExtendingSelection:[anEvent modifierFlags] & CPShiftKeyMask];
}
}
// ===========
// = CONTROL =
// ===========
@@ -1083,7 +1105,12 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
- (void)mouseDown:(CPEvent)anEvent
{
[_tokenField mouseDown:anEvent];
[_tokenField mouseDownOnToken:self withEvent:anEvent];
}
- (void)mouseUp:(CPEvent)anEvent
{
[_tokenField mouseUpOnToken:self withEvent:anEvent];
}
- (void)_delete:(id)sender