mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-26 19:56:49 +00:00
Merge "Handle undoing of reference group changes"
This commit is contained in:
commit
3c911e8451
|
@ -137,9 +137,6 @@ ve.dm.MWReferenceModel.prototype.updateInternalItem = function ( surfaceModel )
|
|||
// Update the group name of all references nodes with the same group and key
|
||||
txs = [];
|
||||
for ( i = 0, len = refNodes.length; i < len; i++ ) {
|
||||
// HACK: Removing and re-inserting nodes to/from the internal list is done
|
||||
// because internal list doesn't yet support attribute changes
|
||||
refNodes[i].removeFromInternalList();
|
||||
txs.push( ve.dm.Transaction.newFromAttributeChanges(
|
||||
doc,
|
||||
refNodes[i].getOuterRange().start,
|
||||
|
@ -147,10 +144,6 @@ ve.dm.MWReferenceModel.prototype.updateInternalItem = function ( surfaceModel )
|
|||
) );
|
||||
}
|
||||
surfaceModel.change( txs );
|
||||
// HACK: Same as above, internal list issues
|
||||
for ( i = 0, len = refNodes.length; i < len; i++ ) {
|
||||
refNodes[i].addToInternalList();
|
||||
}
|
||||
this.listGroup = listGroup;
|
||||
}
|
||||
// Update internal node content
|
||||
|
|
|
@ -25,7 +25,8 @@ ve.dm.MWReferenceNode = function VeDmMWReferenceNode() {
|
|||
// Event handlers
|
||||
this.connect( this, {
|
||||
root: 'onRoot',
|
||||
unroot: 'onUnroot'
|
||||
unroot: 'onUnroot',
|
||||
attributeChange: 'onAttributeChange'
|
||||
} );
|
||||
};
|
||||
|
||||
|
@ -305,10 +306,13 @@ ve.dm.MWReferenceNode.prototype.onUnroot = function () {
|
|||
*/
|
||||
ve.dm.MWReferenceNode.prototype.addToInternalList = function () {
|
||||
if ( this.getRoot() === this.getDocument().getDocumentNode() ) {
|
||||
this.registeredListGroup = this.element.attributes.listGroup;
|
||||
this.registeredListKey = this.element.attributes.listKey;
|
||||
this.registeredListIndex = this.element.attributes.listIndex;
|
||||
this.getDocument().getInternalList().addNode(
|
||||
this.element.attributes.listGroup,
|
||||
this.element.attributes.listKey,
|
||||
this.element.attributes.listIndex,
|
||||
this.registeredListGroup,
|
||||
this.registeredListKey,
|
||||
this.registeredListIndex,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
@ -319,9 +323,9 @@ ve.dm.MWReferenceNode.prototype.addToInternalList = function () {
|
|||
*/
|
||||
ve.dm.MWReferenceNode.prototype.removeFromInternalList = function () {
|
||||
this.getDocument().getInternalList().removeNode(
|
||||
this.element.attributes.listGroup,
|
||||
this.element.attributes.listKey,
|
||||
this.element.attributes.listIndex,
|
||||
this.registeredListGroup,
|
||||
this.registeredListKey,
|
||||
this.registeredListIndex,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
@ -335,6 +339,21 @@ ve.dm.MWReferenceNode.prototype.getClonedElement = function () {
|
|||
return clone;
|
||||
};
|
||||
|
||||
ve.dm.MWReferenceNode.prototype.onAttributeChange = function ( key, from, to ) {
|
||||
if (
|
||||
( key !== 'listGroup' && key !== 'listKey' ) ||
|
||||
( key === 'listGroup' && this.registeredListGroup === to ) ||
|
||||
( key === 'listKey' && this.registeredListKey === to )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Need the old list keys and indexes, so we register them in addToInternalList
|
||||
// They've already been updated in this.element.attributes before this code runs
|
||||
this.removeFromInternalList();
|
||||
this.addToInternalList();
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.dm.modelRegistry.register( ve.dm.MWReferenceNode );
|
||||
|
|
Loading…
Reference in a new issue