mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-12 06:27:01 +00:00
EditCheck: Replace highlights/selection with fragments
'selection' is only used by AddReferenceEditCheck but this can be done in the act method. Provide a method for getting highlight selections from these 'affected fragments' that can be overridden. Change-Id: Ida661682efd8ae99d945f0e310ea3ce12efc8770
This commit is contained in:
parent
13a949e74d
commit
e62327efe0
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
} );
|
||||
|
|
|
@ -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
|
||||
} )
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue