jenkins-bot has submitted this change and it was merged.

Change subject: Split continued link annotations on wordbreaks
......................................................................


Split continued link annotations on wordbreaks

For now this approach is bit of a hack and will hopefully
be replaced with an ability to cursor either side of an
annotation.

Bug: 51463
Change-Id: I701e3d26e06a28fed2d4950b1d418eda80a1fac5
---
M modules/ve/ce/ve.ce.Surface.js
M modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
M modules/ve/dm/ve.dm.Annotation.js
M modules/ve/dm/ve.dm.AnnotationSet.js
4 files changed, 36 insertions(+), 4 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js
index fb46695..1b6904d 100644
--- a/modules/ve/ce/ve.ce.Surface.js
+++ b/modules/ve/ce/ve.ce.Surface.js
@@ -788,6 +788,8 @@
        var data, range, len, annotations, offsetDiff, lengthDiff, 
sameLeadingAndTrailing,
                previousStart, nextStart, newRange,
                previousData, nextData,
+               i, length, annotation, dataString,
+               annotationsLeft, annotationsRight,
                fromLeft = 0,
                fromRight = 0,
                nodeOffset = node.getModel().getOffset();
@@ -874,9 +876,30 @@
        }
        data = nextData.slice( fromLeft, nextData.length - fromRight );
        // Get annotations to the left of new content and apply
-       annotations =
-               this.model.getDocument().data.getAnnotationsFromOffset( 
nodeOffset + 1 + fromLeft );
+       annotations = this.model.getDocument().data.getAnnotationsFromOffset( 
nodeOffset + 1 + fromLeft );
        if ( annotations.getLength() ) {
+               annotationsLeft = 
this.model.getDocument().data.getAnnotationsFromOffset( nodeOffset + fromLeft );
+               annotationsRight = 
this.model.getDocument().data.getAnnotationsFromOffset( nodeOffset + 1 + 
previousData.length - fromRight );
+               for ( i = 0, length = annotations.getLength(); i < length; i++ 
) {
+                       annotation = annotations.get( i );
+                       if ( annotation.constructor.static.splitOnWordbreak ) {
+                               dataString = new ve.dm.DataString( nextData );
+                               if (
+                                       // if no annotation to the right, check 
for wordbreak
+                                       (
+                                               
!annotationsRight.containsIndex( i ) &&
+                                               unicodeJS.wordbreak.isBreak( 
dataString, fromLeft )
+                                       ) ||
+                                       // if no annotation to the left, check 
for wordbreak
+                                       (
+                                               !annotationsLeft.containsIndex( 
i ) &&
+                                               unicodeJS.wordbreak.isBreak( 
dataString, nextData.length - fromRight )
+                                       )
+                               ) {
+                                       annotations.removeAt( i );
+                               }
+                       }
+               }
                ve.dm.Document.addAnnotationsToData( data, annotations );
        }
        newRange = next.range;
diff --git a/modules/ve/dm/annotations/ve.dm.LinkAnnotation.js 
b/modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
index 28bdd6c..194cb0d 100644
--- a/modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
+++ b/modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
@@ -30,6 +30,8 @@
 
 ve.dm.LinkAnnotation.static.matchTagNames = ['a'];
 
+ve.dm.LinkAnnotation.static.splitOnWordbreak = true;
+
 ve.dm.LinkAnnotation.static.toDataElement = function ( domElements ) {
        return {
                'type': 'link',
diff --git a/modules/ve/dm/ve.dm.Annotation.js 
b/modules/ve/dm/ve.dm.Annotation.js
index 85b7373..89933b1 100644
--- a/modules/ve/dm/ve.dm.Annotation.js
+++ b/modules/ve/dm/ve.dm.Annotation.js
@@ -49,6 +49,13 @@
 ve.dm.Annotation.static.applyToAppendedContent = true;
 
 /**
+ * Abandon continuation when a wordbreak is generated
+ *
+ * @type {boolean}
+ */
+ve.dm.Annotation.static.splitOnWordbreak = false;
+
+/**
  * Static function to convert a linear model data element for this annotation 
type back to
  * a DOM element.
  *
diff --git a/modules/ve/dm/ve.dm.AnnotationSet.js 
b/modules/ve/dm/ve.dm.AnnotationSet.js
index bb62a49..b925c1e 100644
--- a/modules/ve/dm/ve.dm.AnnotationSet.js
+++ b/modules/ve/dm/ve.dm.AnnotationSet.js
@@ -87,8 +87,8 @@
  *
  * @method
  * @param {number} [index] If set, only get the annotation at the index
- * @returns {Array|ve.dm.Annotation|undefined} The annotation at index, or an 
array of all
- *   annotation in the set
+ * @returns {ve.dm.Annotation[]|ve.dm.Annotation|undefined} The annotation at 
index, or an array of all
+ *   annotations in the set
  */
 ve.dm.AnnotationSet.prototype.get = function ( index ) {
        if ( index !== undefined ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I701e3d26e06a28fed2d4950b1d418eda80a1fac5
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to