jenkins-bot has submitted this change and it was merged.
Change subject: When editing meta items, modify them rather than rebuiding them
......................................................................
When editing meta items, modify them rather than rebuiding them
When editing the default sort key or a category's sort key, we would just
build a brand new meta item and replace the original item with it. This
destroys whitespace information tracked in the .internal property though,
so the resulting diffs looked pretty bad.
Instead, use ve.extendObject() to base the new meta item on the old one,
changing only what we need to change and keeping .internal (and
htmlAttributes and anything else that may be hiding in there) intact.
Change-Id: I40f4403ea2f2d13542d2e3c8c53e2d7f79515381
---
M modules/ve/ui/dialogs/ve.ui.MWMetaDialog.js
1 file changed, 15 insertions(+), 6 deletions(-)
Approvals:
Esanders: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/ui/dialogs/ve.ui.MWMetaDialog.js
b/modules/ve/ui/dialogs/ve.ui.MWMetaDialog.js
index 10a7481..c9f6b2f 100644
--- a/modules/ve/ui/dialogs/ve.ui.MWMetaDialog.js
+++ b/modules/ve/ui/dialogs/ve.ui.MWMetaDialog.js
@@ -164,7 +164,7 @@
* @param {string} action Action that caused the window to be closed
*/
ve.ui.MWMetaDialog.prototype.onClose = function ( action ) {
- var newDefaultSortKeyItem,
+ var newDefaultSortKeyItem, newDefaultSortKeyItemData,
surfaceModel = this.surface.getModel(),
currentDefaultSortKeyItem = this.getDefaultSortKeyItem();
@@ -181,13 +181,17 @@
}
if ( this.defaultSortKeyChanged ) {
- newDefaultSortKeyItem = new ve.dm.MWDefaultSortMetaItem( {
+ newDefaultSortKeyItemData = {
'type': 'mwDefaultSort',
'attributes': { 'content':
this.defaultSortInput.getValue() }
- } );
+ };
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 );
}
}
@@ -246,13 +250,18 @@
*
* @method
* @param {Object} item category widget item
+ * @param {Object} [oldData] Metadata object that was previously associated
with this item, if any
* @returns {Object} metaBase
*/
-ve.ui.MWMetaDialog.prototype.getCategoryItemForInsertion = function ( item ) {
- return {
+ve.ui.MWMetaDialog.prototype.getCategoryItemForInsertion = function ( item,
oldData ) {
+ var newData = {
'attributes': { 'category': item.name, 'sortkey': item.sortKey
|| '' },
'type': 'mwCategory'
};
+ if ( oldData ) {
+ return ve.extendObject( {}, oldData, newData );
+ }
+ return newData;
};
/**
@@ -367,7 +376,7 @@
*/
ve.ui.MWMetaDialog.prototype.onUpdateSortKey = function ( item ) {
// Replace meta item with updated one
- item.metaItem.replaceWith( this.getCategoryItemForInsertion( item ) );
+ item.metaItem.replaceWith( this.getCategoryItemForInsertion( item,
item.metaItem.getElement() ) );
};
/**
--
To view, visit https://gerrit.wikimedia.org/r/67890
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I40f4403ea2f2d13542d2e3c8c53e2d7f79515381
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits