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