Trevor Parscal has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/71559


Change subject: Category moving improvements
......................................................................

Category moving improvements

Changes:

ve.dm.MetaList.js
* Auto-initialize index to the end of the list (like the docs claim) even when 
not providing an offset

ve.ui.MWCategoryInputWidget.js
* Cleanup fix for not offering to move the last category to the end

ve.ui.MWCategoryWidget.js
* Allow pressing cancel on the meta dialog after moving a category to the end 
without crashing

Change-Id: I45059bda022639f7942f1799a42ecf8a4d962df0
---
M modules/ve/dm/ve.dm.MetaList.js
M modules/ve/ui/widgets/ve.ui.MWCategoryInputWidget.js
M modules/ve/ui/widgets/ve.ui.MWCategoryWidget.js
3 files changed, 17 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/59/71559/1

diff --git a/modules/ve/dm/ve.dm.MetaList.js b/modules/ve/dm/ve.dm.MetaList.js
index 858c7d3..861b06a 100644
--- a/modules/ve/dm/ve.dm.MetaList.js
+++ b/modules/ve/dm/ve.dm.MetaList.js
@@ -251,8 +251,8 @@
  * Insert new metadata into the document. This builds and processes a 
transaction that inserts
  * metadata into the document.
  * @param {Object|ve.dm.MetaItem} meta Metadata element (or MetaItem) to insert
- * @param {Number} [offset] Offset at which to insert the new metadata
- * @param {Number} [index] Index at which to insert the new metadata, or 
undefined to add to the end
+ * @param {Number} [offset] Offset to insert the new metadata, or undefined to 
add to the end
+ * @param {Number} [index] Index to insert the new metadata, or undefined to 
add to the end
  */
 ve.dm.MetaList.prototype.insertMeta = function ( meta, offset, index ) {
        var tx;
@@ -261,8 +261,8 @@
        }
        if ( offset === undefined ) {
                offset = this.document.data.getLength();
-               index = 0;
-       } else  if ( index === undefined ) {
+       }
+       if ( index === undefined ) {
                index = ( this.document.metadata.getData( offset ) || [] 
).length;
        }
        tx = ve.dm.Transaction.newFromMetadataInsertion( this.document, offset, 
index, [ meta ] );
diff --git a/modules/ve/ui/widgets/ve.ui.MWCategoryInputWidget.js 
b/modules/ve/ui/widgets/ve.ui.MWCategoryInputWidget.js
index c9f446f..1eebe89 100644
--- a/modules/ve/ui/widgets/ve.ui.MWCategoryInputWidget.js
+++ b/modules/ve/ui/widgets/ve.ui.MWCategoryInputWidget.js
@@ -106,7 +106,7 @@
                matchingCategories = data || [];
 
        // Existing categories
-       for ( i = 0, len = existingCategories.length; i < len; i++ ) {
+       for ( i = 0, len = existingCategories.length - 1; i < len; i++ ) {
                item = existingCategories[i];
                // Verify that item starts with category.value
                if ( item.lastIndexOf( category.value, 0 ) === 0 ) {
@@ -120,7 +120,7 @@
        for ( i = 0, len = matchingCategories.length; i < len; i++ ) {
                item = matchingCategories[i];
                if (
-                       ve.indexOf( item, existingCategoryItems ) === -1 &&
+                       ve.indexOf( item, existingCategories ) === -1 &&
                        item.lastIndexOf( category.value, 0 ) === 0
                ) {
                        if ( item === category.value ) {
@@ -132,15 +132,6 @@
        // New category
        if ( !exactMatch ) {
                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
diff --git a/modules/ve/ui/widgets/ve.ui.MWCategoryWidget.js 
b/modules/ve/ui/widgets/ve.ui.MWCategoryWidget.js
index 1ccd80c..971debc 100644
--- a/modules/ve/ui/widgets/ve.ui.MWCategoryWidget.js
+++ b/modules/ve/ui/widgets/ve.ui.MWCategoryWidget.js
@@ -104,8 +104,16 @@
  * @param {ve.ui.MenuItemWidget} item Selected item
  */
 ve.ui.MWCategoryWidget.prototype.onLookupMenuItemSelect = function ( item ) {
-       if ( item && item.getData() !== '' ) {
-               this.emit( 'newCategory',  this.input.getCategoryItemFromValue( 
item.getData() ) );
+       var value = item && item.getData();
+
+       if ( value && value !== '' ) {
+               // Remove existing items by value
+               if ( value in this.categories ) {
+                       this.categories[value].metaItem.remove();
+               }
+               // Add new item
+               this.emit( 'newCategory',  this.input.getCategoryItemFromValue( 
value ) );
+               // Reset input
                this.input.setValue( '' );
        }
 };
@@ -196,15 +204,7 @@
                        'savePopupState': 'onSavePopupState',
                        'togglePopupMenu': 'onTogglePopupMenu'
                } );
-               // Auto-remove existing items by value
-               if ( item.value in this.categories ) {
-                       // Save reference to item
-                       existingCategoryItem = this.categories[item.value];
-                       // Removal in model will trigger #removeItems in widget
-                       existingCategoryItem.metaItem.remove();
-                       // Adjust index to compensate for removal
-                       index = Math.max( index - 1, 0 );
-               }
+
                // Index item by value
                this.categories[item.value] = categoryItem;
                // Copy sortKey from old item when "moving"

-- 
To view, visit https://gerrit.wikimedia.org/r/71559
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I45059bda022639f7942f1799a42ecf8a4d962df0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to