[MediaWiki-commits] [Gerrit] Prevent overlapping link annotations - change (mediawiki...VisualEditor)

2013-06-26 Thread Esanders (Code Review)
Esanders has uploaded a new change for review.

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


Change subject: Prevent overlapping link annotations
..

Prevent overlapping link annotations

Use the 'all' mode of SurfaceFragment#getAnnotations to correctly
handle the selections which include linked and non-linked text
in the LinkInspector.

Bug: 50208
Change-Id: I1cab7f3cc4fc9589eced01ad38c59fe5b9622a57
---
M modules/ve/dm/ve.dm.SurfaceFragment.js
M modules/ve/ui/inspectors/ve.ui.LinkInspector.js
M modules/ve/ui/ve.ui.Inspector.js
3 files changed, 12 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/44/70644/1

diff --git a/modules/ve/dm/ve.dm.SurfaceFragment.js 
b/modules/ve/dm/ve.dm.SurfaceFragment.js
index f6c612e..73dd03c 100644
--- a/modules/ve/dm/ve.dm.SurfaceFragment.js
+++ b/modules/ve/dm/ve.dm.SurfaceFragment.js
@@ -353,7 +353,7 @@
  * argument to get all annotations that occur within the fragment.
  *
  * @method
- * @param {boolean} [all] Get annotations cover some of the fragment
+ * @param {boolean} [all] Get annotations which only cover some of the fragment
  * @returns {ve.dm.AnnotationSet} All annotation objects range is covered by
  */
 ve.dm.SurfaceFragment.prototype.getAnnotations = function ( all ) {
diff --git a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js 
b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
index 92d3fe3..2f0551f 100644
--- a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
+++ b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
@@ -72,7 +72,7 @@
 ve.ui.LinkInspector.prototype.onSetup = function () {
var expandedFragment, trimmedFragment, truncatedFragment,
fragment = this.surface.getModel().getFragment( null, true ),
-   annotation = this.getMatchingAnnotations( fragment ).get( 0 );
+   annotation = this.getMatchingAnnotations( fragment, true ).get( 
0 );
 
// Parent method
ve.ui.Inspector.prototype.onSetup.call( this );
@@ -111,7 +111,11 @@
  */
 ve.ui.LinkInspector.prototype.onOpen = function () {
var fragment = this.surface.getModel().getFragment( null, true ),
-   annotation = this.getMatchingAnnotations( fragment ).get( 0 );
+   annotation = this.getMatchingAnnotations( fragment, true ).get( 
0 ),
+   // Note that we don't set the 'all' flag here so that any
+   // non-annotated content is annotated on close
+   initialAnnotation = this.getMatchingAnnotations( fragment 
).get( 0 );
+
 
// Parent method
ve.ui.Inspector.prototype.onOpen.call( this );
@@ -119,7 +123,7 @@
// Wait for animation to complete
setTimeout( ve.bind( function () {
// Setup annotation
-   this.initialAnnotationHash = annotation  ve.getHash( 
annotation );
+   this.initialAnnotationHash = initialAnnotation  ve.getHash( 
initialAnnotation );
this.targetInput.setAnnotation( annotation );
this.targetInput.$input.focus().select();
}, this ), 200 );
@@ -174,7 +178,7 @@
}
if ( clear ) {
// Clear all existing annotations
-   annotations = this.getMatchingAnnotations( fragment ).get();
+   annotations = this.getMatchingAnnotations( fragment, true 
).get();
for ( i = 0, len = annotations.length; i  len; i++ ) {
fragment.annotateContent( 'clear', annotations[i] );
}
diff --git a/modules/ve/ui/ve.ui.Inspector.js b/modules/ve/ui/ve.ui.Inspector.js
index 31b23bb..f173e3b 100644
--- a/modules/ve/ui/ve.ui.Inspector.js
+++ b/modules/ve/ui/ve.ui.Inspector.js
@@ -136,12 +136,13 @@
  *
  * @method
  * @param {ve.dm.SurfaceFragment} fragment Fragment to get matching 
annotations within
+ * @param {boolean} [all] Get annotations which only cover some of the fragment
  * @returns {ve.dm.AnnotationSet} Matching annotations
  */
-ve.ui.Inspector.prototype.getMatchingAnnotations = function ( fragment ) {
+ve.ui.Inspector.prototype.getMatchingAnnotations = function ( fragment, all ) {
var constructor = this.constructor;
 
-   return fragment.getAnnotations().filter( function ( annnotation ) {
+   return fragment.getAnnotations( all ).filter( function ( annnotation ) {
return ve.ui.viewRegistry.isViewRelatedToModel( constructor, 
annnotation );
} );
 };

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1cab7f3cc4fc9589eced01ad38c59fe5b9622a57
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders esand...@wikimedia.org

___
MediaWiki-commits mailing list

[MediaWiki-commits] [Gerrit] Prevent overlapping link annotations - change (mediawiki...VisualEditor)

2013-06-26 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Prevent overlapping link annotations
..


Prevent overlapping link annotations

Use the 'all' mode of SurfaceFragment#getAnnotations to correctly
handle the selections which include linked and non-linked text
in the LinkInspector.

Bug: 50208
Change-Id: I1cab7f3cc4fc9589eced01ad38c59fe5b9622a57
---
M modules/ve/dm/ve.dm.SurfaceFragment.js
M modules/ve/ui/inspectors/ve.ui.LinkInspector.js
M modules/ve/ui/ve.ui.Inspector.js
3 files changed, 12 insertions(+), 7 deletions(-)

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



diff --git a/modules/ve/dm/ve.dm.SurfaceFragment.js 
b/modules/ve/dm/ve.dm.SurfaceFragment.js
index f6c612e..73dd03c 100644
--- a/modules/ve/dm/ve.dm.SurfaceFragment.js
+++ b/modules/ve/dm/ve.dm.SurfaceFragment.js
@@ -353,7 +353,7 @@
  * argument to get all annotations that occur within the fragment.
  *
  * @method
- * @param {boolean} [all] Get annotations cover some of the fragment
+ * @param {boolean} [all] Get annotations which only cover some of the fragment
  * @returns {ve.dm.AnnotationSet} All annotation objects range is covered by
  */
 ve.dm.SurfaceFragment.prototype.getAnnotations = function ( all ) {
diff --git a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js 
b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
index 92d3fe3..2f0551f 100644
--- a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
+++ b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
@@ -72,7 +72,7 @@
 ve.ui.LinkInspector.prototype.onSetup = function () {
var expandedFragment, trimmedFragment, truncatedFragment,
fragment = this.surface.getModel().getFragment( null, true ),
-   annotation = this.getMatchingAnnotations( fragment ).get( 0 );
+   annotation = this.getMatchingAnnotations( fragment, true ).get( 
0 );
 
// Parent method
ve.ui.Inspector.prototype.onSetup.call( this );
@@ -111,7 +111,11 @@
  */
 ve.ui.LinkInspector.prototype.onOpen = function () {
var fragment = this.surface.getModel().getFragment( null, true ),
-   annotation = this.getMatchingAnnotations( fragment ).get( 0 );
+   annotation = this.getMatchingAnnotations( fragment, true ).get( 
0 ),
+   // Note that we don't set the 'all' flag here so that any
+   // non-annotated content is annotated on close
+   initialAnnotation = this.getMatchingAnnotations( fragment 
).get( 0 );
+
 
// Parent method
ve.ui.Inspector.prototype.onOpen.call( this );
@@ -119,7 +123,7 @@
// Wait for animation to complete
setTimeout( ve.bind( function () {
// Setup annotation
-   this.initialAnnotationHash = annotation  ve.getHash( 
annotation );
+   this.initialAnnotationHash = initialAnnotation  ve.getHash( 
initialAnnotation );
this.targetInput.setAnnotation( annotation );
this.targetInput.$input.focus().select();
}, this ), 200 );
@@ -174,7 +178,7 @@
}
if ( clear ) {
// Clear all existing annotations
-   annotations = this.getMatchingAnnotations( fragment ).get();
+   annotations = this.getMatchingAnnotations( fragment, true 
).get();
for ( i = 0, len = annotations.length; i  len; i++ ) {
fragment.annotateContent( 'clear', annotations[i] );
}
diff --git a/modules/ve/ui/ve.ui.Inspector.js b/modules/ve/ui/ve.ui.Inspector.js
index 31b23bb..f173e3b 100644
--- a/modules/ve/ui/ve.ui.Inspector.js
+++ b/modules/ve/ui/ve.ui.Inspector.js
@@ -136,12 +136,13 @@
  *
  * @method
  * @param {ve.dm.SurfaceFragment} fragment Fragment to get matching 
annotations within
+ * @param {boolean} [all] Get annotations which only cover some of the fragment
  * @returns {ve.dm.AnnotationSet} Matching annotations
  */
-ve.ui.Inspector.prototype.getMatchingAnnotations = function ( fragment ) {
+ve.ui.Inspector.prototype.getMatchingAnnotations = function ( fragment, all ) {
var constructor = this.constructor;
 
-   return fragment.getAnnotations().filter( function ( annnotation ) {
+   return fragment.getAnnotations( all ).filter( function ( annnotation ) {
return ve.ui.viewRegistry.isViewRelatedToModel( constructor, 
annnotation );
} );
 };

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1cab7f3cc4fc9589eced01ad38c59fe5b9622a57
Gerrit-PatchSet: 1
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