jenkins-bot has submitted this change and it was merged.

Change subject: Only replace meta-data from dialog if it has changed
......................................................................


Only replace meta-data from dialog if it has changed

Previously we had a defaultSortKeyChanged value that lied - it was
possible for the value to be changed A -> B -> A by the user mid-
edit. However, the meta dialog assumed that defaultSortKeyChanged
wasn't lying, so blindly changed the meta item to the new value,
causing an unnecessary meta change if the user had done a no-op.

Now the value is renamed to defaultSortKeyTouched, and we actually
detect for content changes, and only change the meta item if a
change is actually needed (be that a removal, a replacement, or an
insertion).

Change-Id: I13022090bd7561a460a1151013e2b7d2a029f4dd
---
M modules/ve-mw/ui/dialogs/ve.ui.MWMetaDialog.js
1 file changed, 27 insertions(+), 20 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMetaDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWMetaDialog.js
index d2c1a5a..c4f7201 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWMetaDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMetaDialog.js
@@ -23,7 +23,7 @@
 
        // Properties
        this.metaList = this.surface.getModel().metaList;
-       this.defaultSortKeyChanged = false;
+       this.defaultSortKeyTouched = false;
        this.fallbackDefaultSortKey = mw.config.get( 'wgTitle' );
 
        // Events
@@ -78,7 +78,7 @@
  */
 ve.ui.MWMetaDialog.prototype.onDefaultSortChange = function ( value ) {
        this.categoryWidget.setDefaultSortKey( value === '' ? 
this.fallbackDefaultSortKey : value );
-       this.defaultSortKeyChanged = true;
+       this.defaultSortKeyTouched = true;
 };
 
 /**
@@ -415,7 +415,7 @@
        this.defaultSortInput.setValue(
                defaultSortKeyItem ? defaultSortKeyItem.getAttribute( 'content' 
) : ''
        );
-       this.defaultSortKeyChanged = false;
+       this.defaultSortKeyTouched = false;
 
        // Force all previous transactions to be separate from this history 
state
        surfaceModel.breakpoint();
@@ -434,9 +434,16 @@
        // Data initialization
        data = data || {};
 
-       var hasTransactions, newDefaultSortKeyItem, newDefaultSortKeyItemData,
+       var hasTransactions,
                surfaceModel = this.surface.getModel(),
-               currentDefaultSortKeyItem = this.getDefaultSortKeyItem();
+
+               // Category sort key items
+               currentDefaultSortKeyItem = this.getDefaultSortKeyItem(),
+               newDefaultSortKey = this.defaultSortInput.getValue(),
+               newDefaultSortKeyData = {
+                       'type': 'mwDefaultSort',
+                       'attributes': { 'content': newDefaultSortKey }
+               };
 
        // Place transactions made while dialog was open in a common history 
state
        hasTransactions = surfaceModel.breakpoint();
@@ -447,23 +454,23 @@
                surfaceModel.truncateUndoStack();
        }
 
-       if ( this.defaultSortKeyChanged ) {
-               if ( this.defaultSortInput.getValue() !== '' ) {
-                       newDefaultSortKeyItemData = {
-                               'type': 'mwDefaultSort',
-                               'attributes': { 'content': 
this.defaultSortInput.getValue() }
-                       };
+       // Alter the default sort key iff it's been touched & is actually 
different
+       if ( this.defaultSortKeyTouched ) {
+               if ( newDefaultSortKey === '' ) {
                        if ( currentDefaultSortKeyItem ) {
-                               newDefaultSortKeyItem = new 
ve.dm.MWDefaultSortMetaItem(
-                                       ve.extendObject( {}, 
currentDefaultSortKeyItem.getElement(), newDefaultSortKeyItemData )
-                               );
-                               currentDefaultSortKeyItem.replaceWith( 
newDefaultSortKeyItem );
-                       } else {
-                               newDefaultSortKeyItem = new 
ve.dm.MWDefaultSortMetaItem( newDefaultSortKeyItemData );
-                               this.metaList.insertMeta( newDefaultSortKeyItem 
);
+                               currentDefaultSortKeyItem.remove();
                        }
-               } else if ( currentDefaultSortKeyItem ) {
-                       currentDefaultSortKeyItem.remove();
+               } else {
+                       if ( !currentDefaultSortKeyItem ) {
+                               this.metaList.insertMeta( newDefaultSortKeyData 
);
+                       } else if ( currentDefaultSortKeyItem.getValue() !== 
newDefaultSortKey ) {
+                               currentDefaultSortKeyItem.replaceWith(
+                                       ve.extendObject( true, {},
+                                               
currentDefaultSortKeyItem.getElement(),
+                                               newDefaultSortKeyData
+                                       )
+                               );
+                       }
                }
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I13022090bd7561a460a1151013e2b7d2a029f4dd
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to