Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/197425

Change subject: Expand annotation beyond a word if it exists
......................................................................

Expand annotation beyond a word if it exists

For the annotation inspector, if we start before a word, the
selection expands to fit the word. However, we may also be inside
a bigger annotation already. In that case, we want to run another
test to find the bigger annotation and expand the selection to
cover it as well.

Bug: T86399
Change-Id: I94a468f42e087eb16c68ba80fe74164e7a4875ee
---
M src/ui/inspectors/ve.ui.AnnotationInspector.js
1 file changed, 20 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/25/197425/1

diff --git a/src/ui/inspectors/ve.ui.AnnotationInspector.js 
b/src/ui/inspectors/ve.ui.AnnotationInspector.js
index 3164d6d..2505153 100644
--- a/src/ui/inspectors/ve.ui.AnnotationInspector.js
+++ b/src/ui/inspectors/ve.ui.AnnotationInspector.js
@@ -167,13 +167,13 @@
 ve.ui.AnnotationInspector.prototype.getSetupProcess = function ( data ) {
        return ve.ui.AnnotationInspector.super.prototype.getSetupProcess.call( 
this, data )
                .next( function () {
-                       var expandedFragment, trimmedFragment, 
initialCoveringAnnotation,
+                       var i, len, expandedFragment, trimmedFragment, 
initialCoveringAnnotation,
+                               annotationSet, annotations,
                                fragment = this.getFragment(),
                                surfaceModel = fragment.getSurface(),
                                annotation = this.getMatchingAnnotations( 
fragment, true ).get( 0 );
 
                        surfaceModel.pushStaging();
-
                        // Initialize range
                        if ( this.previousSelection instanceof 
ve.dm.LinearSelection && !annotation ) {
                                if (
@@ -183,11 +183,26 @@
                                        // Expand to nearest word
                                        expandedFragment = 
fragment.expandLinearSelection( 'word' );
                                        fragment = expandedFragment;
+
+                                       // Check if we're inside a relevant 
annotation and if so, define it
+                                       annotationSet = 
fragment.document.data.getAnnotationsFromRange( fragment.selection.range );
+                                       if ( annotationSet.getLength() > 0 ) {
+                                               for ( i = 0, len = 
this.constructor.static.modelClasses.length; i < len; i++ ) {
+                                                       annotations = 
annotationSet.getAnnotationsByName( this.constructor.static.modelClasses[ i 
].static.name );
+                                                       if ( 
annotations.getLength() > 0 ) {
+                                                               // We're in the 
middle of an annotation, let's make sure we expand
+                                                               // our 
selection to include the entire existing annotation
+                                                               fragment = 
fragment.expandLinearSelection( 'annotation', annotations.get( 0 ) );
+                                                               break;
+                                                       }
+                                               }
+                                       }
                                } else {
                                        // Trim whitespace
                                        trimmedFragment = 
fragment.trimLinearSelection();
                                        fragment = trimmedFragment;
                                }
+
                                if ( !fragment.getSelection().isCollapsed() ) {
                                        // Create annotation from selection
                                        annotation = 
this.getAnnotationFromFragment( fragment );
@@ -195,7 +210,9 @@
                                                fragment.annotateContent( 
'set', annotation );
                                        }
                                }
-                       } else {
+                       }
+
+                       if ( annotation ) {
                                // Expand range to cover annotation
                                expandedFragment = 
fragment.expandLinearSelection( 'annotation', annotation );
                                fragment = expandedFragment;

-- 
To view, visit https://gerrit.wikimedia.org/r/197425
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I94a468f42e087eb16c68ba80fe74164e7a4875ee
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to