jenkins-bot has submitted this change and it was merged.
Change subject: Configurable insertion annotations
......................................................................
Configurable insertion annotations
This makes it possible to use a static property to configure whether an
annotation should be applied to content added after it. This makes it
possible to do this for normal style stuff, but not for links.
TODO: Inez is going to add IE support for this since it inverts the
problem where the UI gets out of sync in all non-IE browsers to now make
it so it only gets out of sync in IE.
Bug: 48171
Change-Id: I5f279b06b098960be7bd4ad3f5e6f74b67e31d1a
---
M modules/ve/actions/ve.AnnotationAction.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
M modules/ve/dm/ve.dm.Surface.js
5 files changed, 37 insertions(+), 17 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/actions/ve.AnnotationAction.js
b/modules/ve/actions/ve.AnnotationAction.js
index b9aad5c..7074812 100644
--- a/modules/ve/actions/ve.AnnotationAction.js
+++ b/modules/ve/actions/ve.AnnotationAction.js
@@ -77,7 +77,8 @@
fragment.getAnnotations().containsComparable(
annotation ) ? 'clear' : 'set', name, data
);
} else {
- existingAnnotations =
surfaceModel.getInsertionAnnotations().getComparableAnnotations( annotation );
+ existingAnnotations = surfaceModel
+ .getInsertionAnnotations().getComparableAnnotations(
annotation );
if ( existingAnnotations.isEmpty() ) {
surfaceModel.addInsertionAnnotations( annotation );
} else {
diff --git a/modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
b/modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
index 28bdd6c..433a162 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.applyToAppendedContent = false;
+
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 d0b7a64..8cd28f8 100644
--- a/modules/ve/dm/ve.dm.Annotation.js
+++ b/modules/ve/dm/ve.dm.Annotation.js
@@ -41,6 +41,13 @@
*/
ve.dm.Annotation.static.enableAboutGrouping = false;
+/**
+ * Automatically apply annotation to content inserted after it.
+ *
+ * @type {boolean}
+ */
+ve.dm.Annotation.static.applyToAppendedContent = true;
+
/* Methods */
/**
diff --git a/modules/ve/dm/ve.dm.AnnotationSet.js
b/modules/ve/dm/ve.dm.AnnotationSet.js
index f856bf9..8ef64e9 100644
--- a/modules/ve/dm/ve.dm.AnnotationSet.js
+++ b/modules/ve/dm/ve.dm.AnnotationSet.js
@@ -82,12 +82,13 @@
/**
* Get an annotation or all annotations from the set.
*
- * set.get( 5 ) returns the annotation at index 5, set.get() returns an array
with all annotations in
- * the entire set.
+ * set.get( 5 ) returns the annotation at index 5, set.get() returns an array
with all annotations
+ * in the entire set.
*
* @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 {Array|ve.dm.Annotation|undefined} The annotation at index, or an
array of all
+ * annotation in the set
*/
ve.dm.AnnotationSet.prototype.get = function ( index ) {
if ( index !== undefined ) {
diff --git a/modules/ve/dm/ve.dm.Surface.js b/modules/ve/dm/ve.dm.Surface.js
index 4d2c7e1..5e00207 100644
--- a/modules/ve/dm/ve.dm.Surface.js
+++ b/modules/ve/dm/ve.dm.Surface.js
@@ -297,10 +297,11 @@
if ( !this.enabled ) {
return;
}
- var i, len, offset, annotations,
+ var i, len, left, right, leftAnnotations, rightAnnotations,
insertionAnnotations,
selectedNodes = {},
selectionChange = false,
- contextChange = false;
+ contextChange = false,
+ dataModelData = this.documentModel.data;
// Stop observation polling, things changing right now are known already
this.emit( 'lock' );
@@ -360,28 +361,36 @@
}
}
- // Figure out which offset which we should get insertion annotations
from
+ // Figure out which annotations to use for insertions
if ( this.selection.isCollapsed() ) {
// Get annotations from the left of the cursor
- offset = this.documentModel.data.getNearestContentOffset(
- Math.max( 0, this.selection.start - 1 ), -1
- );
+ left = dataModelData.getNearestContentOffset( Math.max( 0,
this.selection.start - 1 ), -1 );
+ right = dataModelData.getNearestContentOffset( Math.max( 0,
this.selection.start ) );
} else {
// Get annotations from the first character of the selection
- offset = this.documentModel.data.getNearestContentOffset(
this.selection.start );
+ left = dataModelData.getNearestContentOffset(
this.selection.start );
+ right = dataModelData.getNearestContentOffset(
this.selection.end );
}
- if ( offset === -1 ) {
+ if ( left === -1 ) {
// Document is empty, use empty set
- annotations = new ve.dm.AnnotationSet(
this.documentModel.getStore() );
+ insertionAnnotations = new ve.dm.AnnotationSet(
this.documentModel.getStore() );
} else {
- annotations = this.documentModel.data.getAnnotationsFromOffset(
offset );
+ // Include annotations on the left that should be added to
appended content, or ones that
+ // are on both the left and the right that should not
+ leftAnnotations = dataModelData.getAnnotationsFromOffset( left
);
+ rightAnnotations = dataModelData.getAnnotationsFromOffset(
right );
+ insertionAnnotations = leftAnnotations.filter( function (
annotation ) {
+ return
annotation.constructor.static.applyToAppendedContent ||
+ rightAnnotations.containsComparable( annotation
);
+ } );
}
+
// Only emit an annotations change event if there's a meaningful
difference
if (
- !annotations.containsAllOf( this.insertionAnnotations ) ||
- !this.insertionAnnotations.containsAllOf( annotations )
+ !insertionAnnotations.containsAllOf( this.insertionAnnotations
) ||
+ !this.insertionAnnotations.containsAllOf( insertionAnnotations )
) {
- this.setInsertionAnnotations( annotations );
+ this.setInsertionAnnotations( insertionAnnotations );
contextChange = true;
}
--
To view, visit https://gerrit.wikimedia.org/r/62481
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5f279b06b098960be7bd4ad3f5e6f74b67e31d1a
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Inez <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits