diff --git a/editcheck/modules/EditCheckAction.js b/editcheck/modules/EditCheckAction.js index 8d0bccfb87..5cfd6aaa12 100644 --- a/editcheck/modules/EditCheckAction.js +++ b/editcheck/modules/EditCheckAction.js @@ -3,14 +3,12 @@ * * @param {Object} config * @param {mw.editcheck.BaseEditCheck} check - * @param {ve.dm.SurfaceFragment[]} highlights Fragments to highlight - * @param {ve.dm.SurfaceFragment} selection Fragment to select when acting + * @param {ve.dm.SurfaceFragment[]} fragments Affected fragments * @param {jQuery|string|Function|OO.ui.HtmlSnippet} message Check message body */ mw.editcheck.EditCheckAction = function MWEditCheckAction( config ) { this.check = config.check; - this.highlights = config.highlights; - this.selection = config.selection; + this.fragments = config.fragments; this.message = config.message; }; @@ -25,6 +23,15 @@ mw.editcheck.EditCheckAction.prototype.getChoices = function () { return this.check.getChoices( this ); }; +/** + * Get selections to highlight for this check + * + * @return {ve.dm.Selection[]} + */ +mw.editcheck.EditCheckAction.prototype.getHighlightSelections = function () { + return this.fragments.map( ( fragment ) => fragment.getSelection() ); +}; + /** * Get a description of the check * diff --git a/editcheck/modules/EditCheckDialog.js b/editcheck/modules/EditCheckDialog.js index 874ee47c81..8af0141e63 100644 --- a/editcheck/modules/EditCheckDialog.js +++ b/editcheck/modules/EditCheckDialog.js @@ -60,8 +60,8 @@ ve.ui.EditCheckDialog.prototype.update = function () { label: check.message, framed: false } ).$element ); - check.highlights.forEach( ( highlight ) => { - selections.push( ve.ce.Selection.static.newFromModel( highlight.getSelection(), surfaceView ) ); + check.getHighlightSelections().forEach( ( selection ) => { + selections.push( ve.ce.Selection.static.newFromModel( selection, surfaceView ) ); } ); } ); surfaceView.getSelectionManager().drawSelections( 'editCheckWarning', selections ); diff --git a/editcheck/modules/EditCheckFactory.js b/editcheck/modules/EditCheckFactory.js index 2094577a60..0487515075 100644 --- a/editcheck/modules/EditCheckFactory.js +++ b/editcheck/modules/EditCheckFactory.js @@ -78,7 +78,7 @@ mw.editcheck.EditCheckFactory.prototype.createAllByListener = function ( listene } } ); newChecks.sort( - ( a, b ) => a.highlights[ 0 ].getSelection().getCoveringRange().start - b.highlights[ 0 ].getSelection().getCoveringRange().start + ( a, b ) => a.getHighlightSelections()[ 0 ].getCoveringRange().start - b.getHighlightSelections()[ 0 ].getCoveringRange().start ); return newChecks; }; diff --git a/editcheck/modules/editchecks/AddReferenceEditCheck.js b/editcheck/modules/editchecks/AddReferenceEditCheck.js index 4b8b522466..4f2d40470a 100644 --- a/editcheck/modules/editchecks/AddReferenceEditCheck.js +++ b/editcheck/modules/editchecks/AddReferenceEditCheck.js @@ -18,8 +18,7 @@ mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave = function ( surfaceMo return this.findAddedContent( surfaceModel.getDocument() ).map( ( range ) => { const fragment = surfaceModel.getLinearFragment( range ); return new mw.editcheck.EditCheckAction( { - highlights: [ fragment ], - selection: this.adjustForPunctuation( fragment.collapseToEnd() ), + fragments: [ fragment ], check: this } ); } ); @@ -60,7 +59,8 @@ mw.editcheck.AddReferenceEditCheck.prototype.act = function ( choice, action, co switch ( choice ) { case 'accept': ve.track( 'activity.editCheckReferences', { action: 'edit-check-confirm' } ); - action.selection.select(); + + this.adjustForPunctuation( action.fragments[ 0 ].collapseToEnd() ).select(); return windowAction.open( 'citoid' ).then( ( instance ) => instance.closing ).then( ( citoidData ) => { const citoidOrCiteDataDeferred = ve.createDeferred(); @@ -95,7 +95,7 @@ mw.editcheck.AddReferenceEditCheck.prototype.act = function ( choice, action, co return windowAction.open( 'editCheckReferencesInspector', { - fragment: action.highlights[ 0 ], + fragment: action.fragments[ 0 ], callback: contextItem.data.callback, saveProcessDeferred: contextItem.data.saveProcessDeferred } diff --git a/editcheck/modules/editchecks/ConvertReferenceEditCheck.js b/editcheck/modules/editchecks/ConvertReferenceEditCheck.js index d824d7329a..8a93fb112d 100644 --- a/editcheck/modules/editchecks/ConvertReferenceEditCheck.js +++ b/editcheck/modules/editchecks/ConvertReferenceEditCheck.js @@ -22,8 +22,7 @@ mw.editcheck.ConvertReferenceEditCheck.prototype.onDocumentChange = function ( s if ( href ) { const fragment = surfaceModel.getLinearFragment( node.getOuterRange() ); return new mw.editcheck.EditCheckAction( { - highlights: [ fragment ], - selection: fragment, + fragments: [ fragment ], message: ve.msg( 'citoid-referencecontextitem-convert-message' ), check: this } ); diff --git a/editcheck/modules/editchecks/TextMatchEditCheck.js b/editcheck/modules/editchecks/TextMatchEditCheck.js index 6d22a2f530..913eb34ba0 100644 --- a/editcheck/modules/editchecks/TextMatchEditCheck.js +++ b/editcheck/modules/editchecks/TextMatchEditCheck.js @@ -22,8 +22,7 @@ mw.editcheck.TextMatchEditCheck.prototype.onDocumentChange = function ( surfaceM const fragment = surfaceModel.getLinearFragment( range ); actions.push( new mw.editcheck.EditCheckAction( { - highlights: [ fragment ], - selection: fragment, + fragments: [ fragment ], message: replacer.message, check: this } ) diff --git a/editcheck/modules/init.js b/editcheck/modules/init.js index f7f1b1ebb6..df26a8847d 100644 --- a/editcheck/modules/init.js +++ b/editcheck/modules/init.js @@ -153,10 +153,10 @@ if ( mw.config.get( 'wgVisualEditorConfig' ).editCheck || mw.editcheck.ecenable const highlightNodes = []; const selections = []; checks.forEach( ( check ) => { - check.highlights.forEach( ( highlight ) => { - highlightNodes.push.apply( highlightNodes, surfaceView.getDocument().selectNodes( highlight.getSelection().getCoveringRange(), 'branches' ).map( ( spec ) => spec.node ) ); - const selection = ve.ce.Selection.static.newFromModel( highlight.getSelection(), surfaceView ); - selections.push( selection ); + check.getHighlightSelections().forEach( ( selection ) => { + highlightNodes.push.apply( highlightNodes, surfaceView.getDocument().selectNodes( selection.getCoveringRange(), 'branches' ).map( ( spec ) => spec.node ) ); + const selectionView = ve.ce.Selection.static.newFromModel( selection, surfaceView ); + selections.push( selectionView ); } ); } ); // TODO: Make selections clickable when multicheck is enabled @@ -201,7 +201,7 @@ if ( mw.config.get( 'wgVisualEditorConfig' ).editCheck || mw.editcheck.ecenable // eslint-disable-next-line no-inner-declarations function showCheckContext( check ) { - const fragment = check.highlights[ 0 ]; + const fragment = check.fragments[ 0 ]; // Select the found content to correctly position the context on desktop fragment.select();