Improve token field keyboard navigation when tokens are selected.

If one or more token is selected and the left arrow key is pressed, collapse the selection to the left of the first selected token.

Similarly, on right arrow key collapse to the right of the last token.

Note that shift-left and shift-right have no effect if the first or last token respectively in the field are already selected.
This commit is contained in:
Alexander Ljungberg
2012-06-21 19:24:22 +01:00
parent 7764921c21
commit d39849b297
+2 -2
View File
@@ -725,7 +725,7 @@ var CPScrollDestinationNone = 0,
- (void)moveLeft:(id)sender
{
// Left arrow
if (_selectedRange.location > 0 && CPTokenFieldDOMInputElement.value == "")
if ((_selectedRange.location > 0 || _selectedRange.length) && CPTokenFieldDOMInputElement.value == "")
{
if (_selectedRange.length)
// Simply collapse the range.
@@ -762,7 +762,7 @@ var CPScrollDestinationNone = 0,
- (void)moveRight:(id)sender
{
// Right arrow
if (_selectedRange.location < [[self _tokens] count] && CPTokenFieldDOMInputElement.value == "")
if ((_selectedRange.location < [[self _tokens] count] || _selectedRange.length) && CPTokenFieldDOMInputElement.value == "")
{
if (_selectedRange.length)
{