Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/74168
Change subject: [WIP] Split continued link annotations on wordbreaks
......................................................................
[WIP] Split continued link annotations on wordbreaks
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(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/68/74168/1
diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js
index 2d0778f..0eb3799 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 0f8ccc4..ab8badd 100644
--- a/modules/ve/dm/ve.dm.Annotation.js
+++ b/modules/ve/dm/ve.dm.Annotation.js
@@ -48,6 +48,13 @@
*/
ve.dm.Annotation.static.applyToAppendedContent = true;
+/**
+ * Abandon continuation when a wordbreak is generated
+ *
+ * @type {boolean}
+ */
+ve.dm.Annotation.static.splitOnWordbreak = false;
+
/* Methods */
/**
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: newchange
Gerrit-Change-Id: I701e3d26e06a28fed2d4950b1d418eda80a1fac5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits