mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-27 15:50:29 +00:00
Merge "editcheck: Rename shouldApplyToSection to isRangeInValidSection"
This commit is contained in:
commit
b82b2948fe
|
@ -100,26 +100,24 @@ mw.editcheck.BaseEditCheck.prototype.getModifiedRangesFromDiff = function ( diff
|
||||||
return diff.getModifiedRanges( this.constructor.static.onlyCoveredNodes )
|
return diff.getModifiedRanges( this.constructor.static.onlyCoveredNodes )
|
||||||
.filter(
|
.filter(
|
||||||
( range ) => range.getLength() >= this.config.minimumCharacters &&
|
( range ) => range.getLength() >= this.config.minimumCharacters &&
|
||||||
this.shouldApplyToSection( diff.documentModel, range )
|
this.isRangeInValidSection( range, diff.documentModel )
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a modified range is a section we don't ignore (config.ignoreSections)
|
* Check if a modified range is a section we don't ignore (config.ignoreSections)
|
||||||
*
|
*
|
||||||
* @param {ve.dm.Document} documentModel
|
|
||||||
* @param {ve.Range} range
|
* @param {ve.Range} range
|
||||||
|
* @param {ve.dm.Document} documentModel
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
mw.editcheck.BaseEditCheck.prototype.shouldApplyToSection = function ( documentModel, range ) {
|
mw.editcheck.BaseEditCheck.prototype.isRangeInValidSection = function ( range, documentModel ) {
|
||||||
const ignoreSections = this.config.ignoreSections || [];
|
const ignoreSections = this.config.ignoreSections || [];
|
||||||
if ( ignoreSections.length === 0 && !this.config.ignoreLeadSection ) {
|
if ( ignoreSections.length === 0 && !this.config.ignoreLeadSection ) {
|
||||||
// Nothing is forbidden, so everything is permitted
|
// Nothing is forbidden, so everything is permitted
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const isHeading = function ( nodeType ) {
|
const isHeading = ( nodeType ) => nodeType === 'mwHeading';
|
||||||
return nodeType === 'mwHeading';
|
|
||||||
};
|
|
||||||
// Note: we set a limit of 1 here because otherwise this will turn around
|
// Note: we set a limit of 1 here because otherwise this will turn around
|
||||||
// to keep looking when it hits the document boundary:
|
// to keep looking when it hits the document boundary:
|
||||||
const heading = documentModel.getNearestNodeMatching( isHeading, range.start, -1, 1 );
|
const heading = documentModel.getNearestNodeMatching( isHeading, range.start, -1, 1 );
|
||||||
|
@ -138,10 +136,6 @@ mw.editcheck.BaseEditCheck.prototype.shouldApplyToSection = function ( documentM
|
||||||
}
|
}
|
||||||
const compare = new Intl.Collator( documentModel.getLang(), { sensitivity: 'accent' } ).compare;
|
const compare = new Intl.Collator( documentModel.getLang(), { sensitivity: 'accent' } ).compare;
|
||||||
const headingText = documentModel.data.getText( false, heading.getRange() );
|
const headingText = documentModel.data.getText( false, heading.getRange() );
|
||||||
for ( let i = ignoreSections.length - 1; i >= 0; i-- ) {
|
// If the heading text matches any of ignoreSections, return false.
|
||||||
if ( compare( headingText, ignoreSections[ i ] ) === 0 ) {
|
return !ignoreSections.some( ( section ) => compare( headingText, section ) === 0 );
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue