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

Change subject: TextState: Recover annotation models via .data('view').
......................................................................


TextState: Recover annotation models via .data('view').

Bug: T115001
Change-Id: Ib55dc3d786d68bb261ba6e59e9b0399b0273cb55
---
M src/ce/annotations/ve.ce.LinkAnnotation.js
M src/ce/ve.ce.Annotation.js
M src/ce/ve.ce.TextState.js
3 files changed, 31 insertions(+), 18 deletions(-)

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



diff --git a/src/ce/annotations/ve.ce.LinkAnnotation.js 
b/src/ce/annotations/ve.ce.LinkAnnotation.js
index d5c87ac..77f79a7 100644
--- a/src/ce/annotations/ve.ce.LinkAnnotation.js
+++ b/src/ce/annotations/ve.ce.LinkAnnotation.js
@@ -26,7 +26,8 @@
                .prop( {
                        href: ve.resolveUrl( this.model.getHref(), 
this.getModelHtmlDocument() ),
                        title: this.constructor.static.getDescription( 
this.model )
-               } );
+               } )
+               .data( 'view', this );
 };
 
 /* Inheritance */
diff --git a/src/ce/ve.ce.Annotation.js b/src/ce/ve.ce.Annotation.js
index a853699..a7dba22 100644
--- a/src/ce/ve.ce.Annotation.js
+++ b/src/ce/ve.ce.Annotation.js
@@ -26,6 +26,7 @@
 
        // Properties
        this.parentNode = parentNode || null;
+       this.$element.data( 'view', this );
 };
 
 /* Inheritance */
diff --git a/src/ce/ve.ce.TextState.js b/src/ce/ve.ce.TextState.js
index 6bfd90b..ea57f4f 100644
--- a/src/ce/ve.ce.TextState.js
+++ b/src/ce/ve.ce.TextState.js
@@ -169,7 +169,7 @@
        var change, i, iLen, textStart, textEnd, changeOffset, removed, 
removeRange,
                annotations, missing, oldChunk, newChunk, j, jStart, jEnd, 
leastMissing,
                matchStartOffset, matchOffset, bestOffset, jLen, 
oldAnnotations, element,
-               modelClass, ann, oldAnn, data,
+               modelClass, ann, oldAnn, data, view,
                oldChunks = prev.chunks,
                newChunks = this.chunks,
                modelData = modelDoc.data,
@@ -376,22 +376,33 @@
                        annotations = new ve.dm.AnnotationSet( 
modelData.getStore() );
                        for ( j = 0, jLen = newChunk.elements.length; j < jLen; 
j++ ) {
                                element = newChunk.elements[ j ];
-                               modelClass = ve.dm.modelRegistry.lookup(
-                                       ve.dm.modelRegistry.matchElement( 
element )
-                               );
-                               ann = ve.dm.annotationFactory.createFromElement(
-                                       ve.dm.converter.createDataElements( 
modelClass, [ element ] )[ 0 ]
-                               );
-                               if ( !( ann instanceof ve.dm.Annotation ) ) {
-                                       // Erroneous element; nothing we can do 
with it
-                                       continue;
-                               }
-                               oldAnn = oldAnnotations.getComparable( ann );
-                               if ( oldAnn ) {
-                                       ann = oldAnn;
-                               } else if ( 
!ann.constructor.static.inferFromDom ) {
-                                       // New and un-whitelisted: drop the 
annotation
-                                       continue;
+                               // Recover the node from jQuery data store. 
This can only break if the browser
+                               // completely rebuilds the node, but should 
work in cases like typing into
+                               // collapsed links because nails ensure the 
link is never completely empty.
+                               view = $( element ).data( 'view' );
+                               if ( view ) {
+                                       ann = view.getModel();
+                               } else {
+                                       // No view: new annotation element (or 
replacement one):
+                                       // see 
https://phabricator.wikimedia.org/T116269 and
+                                       // 
https://code.google.com/p/chromium/issues/detail?id=54646
+                                       modelClass = ve.dm.modelRegistry.lookup(
+                                               
ve.dm.modelRegistry.matchElement( element )
+                                       );
+                                       ann = 
ve.dm.annotationFactory.createFromElement(
+                                               
ve.dm.converter.createDataElements( modelClass, [ element ] )[ 0 ]
+                                       );
+                                       if ( !( ann instanceof ve.dm.Annotation 
) ) {
+                                               // Erroneous element; nothing 
we can do with it
+                                               continue;
+                                       }
+                                       oldAnn = oldAnnotations.getComparable( 
ann );
+                                       if ( oldAnn ) {
+                                               ann = oldAnn;
+                                       } else if ( 
!ann.constructor.static.inferFromDom ) {
+                                               // New and un-whitelisted: drop 
the annotation
+                                               continue;
+                                       }
                                }
                                annotations.add( ann, annotations.getLength() );
                        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib55dc3d786d68bb261ba6e59e9b0399b0273cb55
Gerrit-PatchSet: 5
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Divec <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to