Merge "[refactor] Update some usages to new refs interface"

This commit is contained in:
jenkins-bot 2024-08-29 12:23:14 +00:00 committed by Gerrit Code Review
commit 1bae4d71c9
4 changed files with 19 additions and 23 deletions

View file

@ -246,15 +246,13 @@ ve.ui.MWReferenceEditPanel.prototype.setFormFieldsFromRef = function ( ref ) {
* @param {ve.dm.MWReferenceModel} ref
*/
ve.ui.MWReferenceEditPanel.prototype.updateReuseWarningFromRef = function ( ref ) {
const group = this.internalList.getNodeGroup( ref.getListGroup() );
const nodes = ve.getProp( group, 'keyedNodes', ref.getListKey() );
const usages = nodes ? nodes.filter(
( node ) => !node.findParent( ve.dm.MWReferencesListNode )
).length : 0;
const usageCount = ve.dm.MWDocumentReferences.static.refsForDoc( this.internalList.getDocument() )
.getGroupRefs( ref.getListGroup() )
.getRefUsages( ref.getListKey() )
.length;
this.reuseWarning
.toggle( usages > 1 )
.setLabel( mw.msg( 'cite-ve-dialog-reference-editing-reused-long', usages ) );
.toggle( usageCount > 1 )
.setLabel( mw.msg( 'cite-ve-dialog-reference-editing-reused-long', usageCount ) );
};
/**
@ -263,15 +261,18 @@ ve.ui.MWReferenceEditPanel.prototype.updateReuseWarningFromRef = function ( ref
*/
ve.ui.MWReferenceEditPanel.prototype.updateExtendsWarningFromRef = function ( ref ) {
if ( ref.extendsRef ) {
const mainRefId = this.internalList.keys.indexOf( ref.extendsRef );
const parentNode = ve.dm.MWDocumentReferences.static.refsForDoc( this.internalList.getDocument() )
.getGroupRefs( ref.getListGroup() )
.getInternalModelNode( ref.extendsRef );
this.extendsWarning.setLabel(
$( '<p>' )
.text( mw.msg( 'cite-ve-dialog-reference-editing-extends' ) )
.append( mainRefId === -1 ?
.append( parentNode ?
new ve.ui.MWPreviewElement( parentNode, { useView: true } ).$element :
$( '<div>' )
.addClass( 've-ui-mwReferenceContextItem-muted' )
.text( ve.msg( 'cite-ve-dialog-reference-missing-parent-ref' ) ) :
new ve.ui.MWPreviewElement( this.internalList.getItemNode( mainRefId ), { useView: true } ).$element )
.text( ve.msg( 'cite-ve-dialog-reference-missing-parent-ref' ) )
)
);
this.extendsWarning.toggle( true );
} else {

View file

@ -172,7 +172,7 @@ ve.ui.MWReferenceSearchWidget.prototype.buildSearchIndex = function () {
let $element;
// Make visible text, citation and reference name searchable
let text = ( citation + ' ' + name ).toLowerCase();
const itemNode = this.internalList.getItemNode( node.getAttribute( 'listIndex' ) );
const itemNode = groupRefs.getInternalModelNode( listKey );
if ( itemNode.length ) {
$element = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element;
text = $element.text().toLowerCase() + ' ' + text;

View file

@ -6,15 +6,9 @@ QUnit.test( 'setReferenceForEditing', ( assert ) => {
ve.init.target.surface = { commandRegistry: { registry: {} } };
const editPanel = new ve.ui.MWReferenceEditPanel();
const emptyDoc = new ve.dm.Document( [
{ type: 'paragraph', internal: { generated: 'empty' } },
{ type: '/paragraph' },
{ type: 'internalList' },
{ type: '/internalList' }
] );
const ref = new ve.dm.MWReferenceModel( emptyDoc );
editPanel.setInternalList( emptyDoc.getInternalList() );
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
const ref = new ve.dm.MWReferenceModel( doc );
editPanel.setInternalList( doc.getInternalList() );
const changeHandlerStub = sinon.stub();
editPanel.connect( changeHandlerStub );

View file

@ -11,7 +11,8 @@ function getInternalListMock( hasNode ) {
default: return undefined;
}
},
getAttributes: () => ( {} )
getAttributes: () => ( {} ),
getInternalItem: () => ( {} )
} : {};
const groups = hasNode ? {
'mwReference/': {