From 793a1364aace0e9a4ba38a800642cd984abaaa27 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Tue, 5 Nov 2024 11:41:50 +0000 Subject: [PATCH] Allow multiple highlight fragments to be passed to an edit check Change-Id: Ie9d7010a1a0ee6a5c570d4fd6988fc876afdb9e2 --- editcheck/modules/AddReferenceEditCheck.js | 4 ++-- editcheck/modules/ConvertReferenceEditCheck.js | 2 +- editcheck/modules/EditCheckAction.js | 2 +- editcheck/modules/EditCheckDialog.js | 4 +++- editcheck/modules/EditCheckFactory.js | 2 +- editcheck/modules/TextMatchEditCheck.js | 2 +- editcheck/modules/init.js | 10 ++++++---- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/editcheck/modules/AddReferenceEditCheck.js b/editcheck/modules/AddReferenceEditCheck.js index a265b6afe4..6f6c4c419e 100644 --- a/editcheck/modules/AddReferenceEditCheck.js +++ b/editcheck/modules/AddReferenceEditCheck.js @@ -13,7 +13,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( { - highlight: fragment, + highlights: [ fragment ], selection: this.adjustForPunctuation( fragment.collapseToEnd() ), check: this } ); @@ -83,7 +83,7 @@ mw.editcheck.AddReferenceEditCheck.prototype.act = function ( choice, action, co return windowAction.open( 'editCheckReferencesInspector', { - fragment: action.highlight, + fragment: action.highlights[ 0 ], callback: contextItem.data.callback, saveProcessDeferred: contextItem.data.saveProcessDeferred } diff --git a/editcheck/modules/ConvertReferenceEditCheck.js b/editcheck/modules/ConvertReferenceEditCheck.js index dc1d3024d4..f46c53feb0 100644 --- a/editcheck/modules/ConvertReferenceEditCheck.js +++ b/editcheck/modules/ConvertReferenceEditCheck.js @@ -22,7 +22,7 @@ mw.editcheck.ConvertReferenceEditCheck.prototype.onDocumentChange = function ( s if ( href ) { const fragment = surfaceModel().getLinearFragment( node.getOuterRange() ); return new mw.editcheck.EditCheckAction( { - highlight: fragment, + highlights: [ fragment ], selection: fragment, message: ve.msg( 'citoid-referencecontextitem-convert-message' ), check: this diff --git a/editcheck/modules/EditCheckAction.js b/editcheck/modules/EditCheckAction.js index a979e6879d..219eef3443 100644 --- a/editcheck/modules/EditCheckAction.js +++ b/editcheck/modules/EditCheckAction.js @@ -1,6 +1,6 @@ mw.editcheck.EditCheckAction = function MWEditCheckAction( config ) { this.check = config.check; - this.highlight = config.highlight; + this.highlights = config.highlights; this.selection = config.selection; this.message = config.message; }; diff --git a/editcheck/modules/EditCheckDialog.js b/editcheck/modules/EditCheckDialog.js index d37764339c..874ee47c81 100644 --- a/editcheck/modules/EditCheckDialog.js +++ b/editcheck/modules/EditCheckDialog.js @@ -60,7 +60,9 @@ ve.ui.EditCheckDialog.prototype.update = function () { label: check.message, framed: false } ).$element ); - selections.push( ve.ce.Selection.static.newFromModel( check.highlight.getSelection(), surfaceView ) ); + check.highlights.forEach( ( highlight ) => { + selections.push( ve.ce.Selection.static.newFromModel( highlight.getSelection(), surfaceView ) ); + } ); } ); surfaceView.getSelectionManager().drawSelections( 'editCheckWarning', selections ); this.$body.empty().append( $checks ); diff --git a/editcheck/modules/EditCheckFactory.js b/editcheck/modules/EditCheckFactory.js index 1d32e9ef37..200f325880 100644 --- a/editcheck/modules/EditCheckFactory.js +++ b/editcheck/modules/EditCheckFactory.js @@ -66,7 +66,7 @@ mw.editcheck.EditCheckFactory.prototype.createAllByListener = function ( listene } } ); newChecks.sort( - ( a, b ) => a.highlight.getSelection().getCoveringRange().start - b.highlight.getSelection().getCoveringRange().start + ( a, b ) => a.highlights[ 0 ].getSelection().getCoveringRange().start - b.highlights[ 0 ].getSelection().getCoveringRange().start ); return newChecks; }; diff --git a/editcheck/modules/TextMatchEditCheck.js b/editcheck/modules/TextMatchEditCheck.js index 3260b87719..6d22a2f530 100644 --- a/editcheck/modules/TextMatchEditCheck.js +++ b/editcheck/modules/TextMatchEditCheck.js @@ -22,7 +22,7 @@ mw.editcheck.TextMatchEditCheck.prototype.onDocumentChange = function ( surfaceM const fragment = surfaceModel.getLinearFragment( range ); actions.push( new mw.editcheck.EditCheckAction( { - highlight: fragment, + highlights: [ fragment ], selection: fragment, message: replacer.message, check: this diff --git a/editcheck/modules/init.js b/editcheck/modules/init.js index adb12edd1c..6a797a4374 100644 --- a/editcheck/modules/init.js +++ b/editcheck/modules/init.js @@ -204,9 +204,11 @@ if ( mw.config.get( 'wgVisualEditorConfig' ).editCheck || mw.editcheck.ecenable const highlightNodes = []; const selections = []; checks.forEach( ( check ) => { - highlightNodes.push.apply( highlightNodes, surfaceView.getDocument().selectNodes( check.highlight.getSelection().getCoveringRange(), 'branches' ).map( ( spec ) => spec.node ) ); - const selection = ve.ce.Selection.static.newFromModel( check.highlight.getSelection(), surfaceView ); - selections.push( selection ); + 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 ); + } ); } ); // TODO: Make selections clickable when multicheck is enabled surfaceView.getSelectionManager().drawSelections( @@ -250,7 +252,7 @@ if ( mw.config.get( 'wgVisualEditorConfig' ).editCheck || mw.editcheck.ecenable // eslint-disable-next-line no-inner-declarations function showCheckContext( check ) { - const fragment = check.highlight; + const fragment = check.highlights[ 0 ]; // Select the found content to correctly position the context on desktop fragment.select();