From 8a7b6054ef0941979246c3b9b229ee69435f353a Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sat, 23 Oct 2010 16:58:02 -0300 Subject: [PATCH] If the text editing part of the token field is the last in the line, make it take up the remaining field width so that it captures clicks there. --- AppKit/CPTokenField.j | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/AppKit/CPTokenField.j b/AppKit/CPTokenField.j index cefa84aa2..22145a0c9 100755 --- a/AppKit/CPTokenField.j +++ b/AppKit/CPTokenField.j @@ -930,15 +930,20 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", return r; } - var placeEditor = function() + var placeEditor = function(useRemainingWidth) { var element = [self _inputElement]; - // XXX The "X" here is used to estimate the space needed to fit the next character - // without clipping. Since different fonts might have different sizes of "X" this - // solution is not ideal, but it works. - var textWidth = _selectedRange.length ? 1 : [(element.value || @"") + "X" sizeWithFont:[self font]].width, - inputFrame = fitAndFrame(textWidth, tokenHeight); + var textWidth = 1; + if (_selectedRange.length === 0) + { + // XXX The "X" here is used to estimate the space needed to fit the next character + // without clipping. Since different fonts might have different sizes of "X" this + // solution is not ideal, but it works. + textWidth = useRemainingWidth ? contentSize.width - offset.x - 1 : [(element.value || @"") + "X" sizeWithFont:[self font]].width; + } + + var inputFrame = fitAndFrame(textWidth, tokenHeight); element.style.left = inputFrame.origin.x + "px"; element.style.top = inputFrame.origin.y + "px"; @@ -953,7 +958,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", for (var i = 0, count = [tokens count]; i < count; i++) { if (isEditing && i == CPMaxRange(_selectedRange)) - placeEditor(i); + placeEditor(false); var tokenView = [tokens objectAtIndex:i]; @@ -972,7 +977,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", } if (isEditing && CPMaxRange(_selectedRange) >= [tokens count]) - placeEditor(); + placeEditor(true); // Hide the editor if there are selected tokens, but still keep it active // so we can continue using our standard keyboard handling events.