diff --git a/editcheck/modules/BaseEditCheck.js b/editcheck/modules/BaseEditCheck.js index 0eb3246c34..33fc9e995a 100644 --- a/editcheck/modules/BaseEditCheck.js +++ b/editcheck/modules/BaseEditCheck.js @@ -274,3 +274,45 @@ mw.editcheck.BaseEditCheck.prototype.isRangeInValidSection = function ( range, d // If the heading text matches any of ignoreSections, return false. return !ignoreSections.some( ( section ) => compare( headingText, section ) === 0 ); }; + +/** + * Dismiss a check action + * + * @param {mw.editCheck.EditCheckAction} action + */ +mw.editcheck.BaseEditCheck.prototype.dismiss = function ( action ) { + const name = this.constructor.static.name; + if ( action.id ) { + const dismissedIds = mw.editcheck.dismissedIds; + dismissedIds[ name ] = dismissedIds[ name ] || []; + dismissedIds[ name ].push( action.id ); + } else { + const dismissedFragments = mw.editcheck.dismissedFragments; + dismissedFragments[ name ] = dismissedFragments[ name ] || []; + dismissedFragments[ name ].push( ...action.fragments ); + } +}; + +/** + * Check if this type of check has been dismissed covering a specific range + * + * @param {ve.Range} range + * @return {boolean} + */ +mw.editcheck.BaseEditCheck.prototype.isDismissedRange = function ( range ) { + const fragments = mw.editcheck.dismissedFragments[ this.constructor.static.name ]; + return !!fragments && fragments.some( + ( fragment ) => fragment.getSelection().getCoveringRange().containsRange( range ) + ); +}; + +/** + * Check if an action with a given ID has been dismissed + * + * @param {string} id + * @return {boolean} + */ +mw.editcheck.BaseEditCheck.prototype.isDismissedId = function ( id ) { + const ids = mw.editcheck.dismissedIds[ this.constructor.static.name ]; + return ids && ids.indexOf( id ) !== -1; +}; diff --git a/editcheck/modules/EditCheckAction.js b/editcheck/modules/EditCheckAction.js index 7cf980f97e..5881e6ea90 100644 --- a/editcheck/modules/EditCheckAction.js +++ b/editcheck/modules/EditCheckAction.js @@ -11,6 +11,7 @@ mw.editcheck.EditCheckAction = function MWEditCheckAction( config ) { this.check = config.check; this.fragments = config.fragments; this.message = config.message; + this.id = config.id; this.title = config.title; this.icon = config.icon; this.type = config.type || 'warning'; diff --git a/editcheck/modules/EditCheckDialog.js b/editcheck/modules/EditCheckDialog.js index dcd5cb2cd4..34766a7905 100644 --- a/editcheck/modules/EditCheckDialog.js +++ b/editcheck/modules/EditCheckDialog.js @@ -317,12 +317,7 @@ ve.ui.EditCheckDialog.prototype.onAct = function ( widget, choice, actionChosen, setTimeout( () => this.surface.getModel().setNullSelection(), 300 ); } - if ( !data ) { - // Nothing happened, just fall back and leave the check - return; - } - - if ( this.listener === 'onBeforeSave' ) { + if ( data && this.listener === 'onBeforeSave' ) { // If an action has been taken, we want to linger for a brief moment // to show the result of the action before moving away // TODO: This was written for AddReferenceEditCheck but should be @@ -334,6 +329,8 @@ ve.ui.EditCheckDialog.prototype.onAct = function ( widget, choice, actionChosen, this.currentOffset = Math.max( 0, this.currentOffset - 1 ); this.update(); }, pause ); + } else { + this.updateDebounced(); } } ); }; diff --git a/editcheck/modules/editchecks/AddReferenceEditCheck.js b/editcheck/modules/editchecks/AddReferenceEditCheck.js index c66f7da5e2..b4090d915f 100644 --- a/editcheck/modules/editchecks/AddReferenceEditCheck.js +++ b/editcheck/modules/editchecks/AddReferenceEditCheck.js @@ -17,14 +17,13 @@ mw.editcheck.AddReferenceEditCheck.static.defaultConfig = ve.extendObject( {}, m } ); mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave = function ( surfaceModel ) { - return this.findAddedContent( surfaceModel.getDocument() ).map( ( range ) => { - const fragment = surfaceModel.getLinearFragment( range ); - return new mw.editcheck.EditCheckAction( { - fragments: [ fragment ], - check: this - // icon: 'quotes', - } ); - } ); + return this.findAddedContent( surfaceModel.getDocument() ).filter( ( range ) => !this.isDismissedRange( range ) ) + .map( + ( range ) => new mw.editcheck.EditCheckAction( { + fragments: [ surfaceModel.getLinearFragment( range ) ], + check: this + } ) + ); }; mw.editcheck.AddReferenceEditCheck.prototype.onDocumentChange = mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave; @@ -100,6 +99,7 @@ mw.editcheck.AddReferenceEditCheck.prototype.act = function ( choice, action, su } ).done( ( data ) => { if ( data && data.action === 'reject' && data.reason ) { mw.editcheck.rejections.push( data.reason ); + this.dismiss( action ); } } ); } diff --git a/editcheck/modules/init.js b/editcheck/modules/init.js index e21e7cc605..164daba9f3 100644 --- a/editcheck/modules/init.js +++ b/editcheck/modules/init.js @@ -1,6 +1,8 @@ mw.editcheck = { config: require( './config.json' ), - ecenable: !!( new URL( location.href ).searchParams.get( 'ecenable' ) || window.MWVE_FORCE_EDIT_CHECK_ENABLED ) + ecenable: !!( new URL( location.href ).searchParams.get( 'ecenable' ) || window.MWVE_FORCE_EDIT_CHECK_ENABLED ), + dismissedFragments: {}, + dismissedIds: {} }; require( './EditCheckContextItem.js' );