Rewrite a conditional to make the logic a little clearer.

I spent a couple minutes looking at this before I saw that we needed
`this.updateVisibility()` to only fire if the loop iterated at least
once.

Change-Id: I7d03f73a35e3ded539898effa064dc0e14ba595f
This commit is contained in:
Zoë 2024-07-08 15:27:07 +01:00
parent 12ef5b7471
commit 652e140dc5

View file

@ -96,11 +96,11 @@ ve.ui.MWTocWidget.prototype.onMetaListRemove = function ( metaItem ) {
* Initialize TOC based on the presence of magic words * Initialize TOC based on the presence of magic words
*/ */
ve.ui.MWTocWidget.prototype.initFromMetaList = function () { ve.ui.MWTocWidget.prototype.initFromMetaList = function () {
const items = this.metaList.getItemsInGroup( 'mwTOC' ), const items = this.metaList.getItemsInGroup( 'mwTOC' );
len = items.length; if ( items.length === 0 ) {
let i = 0; return;
if ( len > 0 ) { }
for ( ; i < len; i++ ) { for ( let i = 0; i < items.length; i++ ) {
if ( items[ i ] instanceof ve.dm.MWTOCMetaItem ) { if ( items[ i ] instanceof ve.dm.MWTOCMetaItem ) {
const property = items[ i ].getAttribute( 'property' ); const property = items[ i ].getAttribute( 'property' );
if ( property === 'mw:PageProp/forcetoc' ) { if ( property === 'mw:PageProp/forcetoc' ) {
@ -112,7 +112,6 @@ ve.ui.MWTocWidget.prototype.initFromMetaList = function () {
} }
} }
this.updateVisibility(); this.updateVisibility();
}
}; };
/** /**