mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Merge "Category moving improvements"
This commit is contained in:
commit
9ec83c11f7
|
@ -251,8 +251,8 @@ ve.dm.MetaList.prototype.getAllItems = function () {
|
|||
* 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 @@ ve.dm.MetaList.prototype.insertMeta = function ( meta, offset, index ) {
|
|||
}
|
||||
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 ] );
|
||||
|
|
|
@ -106,7 +106,7 @@ ve.ui.MWCategoryInputWidget.prototype.getLookupMenuItemsFromData = function ( da
|
|||
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 @@ ve.ui.MWCategoryInputWidget.prototype.getLookupMenuItemsFromData = function ( da
|
|||
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 ) {
|
||||
|
@ -134,15 +134,6 @@ 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(
|
||||
|
|
|
@ -104,8 +104,16 @@ ve.ui.MWCategoryWidget.prototype.onLookupInputKeyDown = function ( e ) {
|
|||
* @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 @@ ve.ui.MWCategoryWidget.prototype.addItems = function ( items, index ) {
|
|||
'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"
|
||||
|
|
Loading…
Reference in a new issue