Actually fix bug 48556

Turns out that by skipping the last item, the following logic which
depended on that item being in the existing items list failed to keep
it's grubby hands off it.

Yes, I know I +2'd it. Shame on me too.

Bug: 48556
Bug: 48565
I93ce05f7cbb28313a3f0827539f0528c366aeb7e

Change-Id: If48e001b92c217bee0a35b6da41d1c1ff0e3271c
This commit is contained in:
Trevor Parscal 2013-06-11 18:52:39 -07:00 committed by Trevor Parscal
parent 75d36e5b32
commit 18cde8a420

View file

@ -106,8 +106,7 @@ ve.ui.MWCategoryInputWidget.prototype.getLookupMenuItemsFromData = function ( da
matchingCategories = data || [];
// Existing categories
// bug 48556: Don't offer the very last category in the list here, so go up to .length - 1
for ( i = 0, len = existingCategories.length - 1; i < len; i++ ) {
for ( i = 0, len = existingCategories.length; i < len; i++ ) {
item = existingCategories[i];
// Verify that item starts with category.value
if ( item.lastIndexOf( category.value, 0 ) === 0 ) {
@ -121,7 +120,7 @@ ve.ui.MWCategoryInputWidget.prototype.getLookupMenuItemsFromData = function ( da
for ( i = 0, len = matchingCategories.length; i < len; i++ ) {
item = matchingCategories[i];
if (
existingCategoryItems.indexOf( item ) === -1 &&
ve.indexOf( item, existingCategoryItems ) === -1 &&
item.lastIndexOf( category.value, 0 ) === 0
) {
if ( item === category.value ) {
@ -135,6 +134,15 @@ ve.ui.MWCategoryInputWidget.prototype.getLookupMenuItemsFromData = function ( da
newCategoryItems.push( category.value );
}
// bug 48556: Don't actually offer to move the very last category in the list - we kept it in
// the list thus far so that other lists would not grab it for themselves, but now it's time to
// say goodbye
if (
existingCategoryItems[existingCategoryItems.length - 1] ===
existingCategories[existingCategories.length - 1] ) {
existingCategoryItems.pop();
}
// Add sections for non-empty groups
if ( newCategoryItems.length ) {
items.push( new ve.ui.MenuSectionItemWidget(
@ -158,8 +166,8 @@ ve.ui.MWCategoryInputWidget.prototype.getLookupMenuItemsFromData = function ( da
items.push( new ve.ui.MenuSectionItemWidget(
'matchingCategories', { '$$': menu$$, 'label': ve.msg( 'visualeditor-dialog-meta-categories-input-matchingcategorieslabel' ) }
) );
for ( i = 0, len = matchingCategories.length; i < len; i++ ) {
item = matchingCategories[i];
for ( i = 0, len = matchingCategoryItems.length; i < len; i++ ) {
item = matchingCategoryItems[i];
items.push( new ve.ui.MenuItemWidget( item, { '$$': menu$$, 'label': item } ) );
}
}