Sophivorus has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/345655 )

Change subject: Update citations when a reference name changes
......................................................................


Update citations when a reference name changes

Bug: T154258
Change-Id: Ic71a580c64ffbe2c980be8d207b76db0132ef157
---
M proveit.js
1 file changed, 24 insertions(+), 20 deletions(-)

Approvals:
  Sophivorus: Verified; Looks good to me, approved



diff --git a/proveit.js b/proveit.js
index 9ed454e..1c2e381 100755
--- a/proveit.js
+++ b/proveit.js
@@ -440,7 +440,20 @@
                };
 
                /**
-                * Highlight the citation in the textbox and scroll it to view
+                * Update this citation in the textbox
+                */
+               this.update = function () {
+                       var oldString = this.string;
+                       this.string = this.toString();
+                       var newString = this.string,
+                               textbox = proveit.getTextbox(),
+                               text = textbox.val();
+                       text = text.replace( oldString, newString );
+                       textbox.val( text );
+               };
+
+               /**
+                * Highlight this citation in the textbox and scroll it to view
                 *
                 * @return {void}
                 */
@@ -521,15 +534,14 @@
                        var reference = event.data;
 
                        // If the reference has no name, ask the user for one
-                       // @todo check if the name is unique?
-                       // @todo autogenerate names?
+                       // @todo check if the name is unique
                        if ( !reference.name ) {
                                reference.name = prompt( proveit.getMessage( 
'prompt-name' ) );
                                if ( !reference.name ) {
                                        return;
                                }
-                               var table = reference.toTable();
-                               $( '#proveit-reference-table' ).replaceWith( 
table );
+
+                               $( '#proveit-reference-table' ).replaceWith( 
reference.toTable() );
 
                                var oldString = reference.string;
                                reference.loadFromForm();
@@ -598,26 +610,18 @@
                        var newName = reference.name,
                                newString = reference.string;
 
-                       // Replace the old reference
+                       // Update the textbox
                        var textbox = proveit.getTextbox(),
                                text = textbox.val();
                        text = text.replace( oldString, newString );
-
-                       // If the name changed, update the citations
-                       // @todo citation.update()
-                       if ( oldName !== newName && reference.citations ) {
-                               var oldCitationString, newCitationString;
-                               reference.citations.forEach( function ( 
citation ) {
-                                       oldCitationString = citation.toString();
-                                       citation.name = newName;
-                                       newCitationString = citation.toString();
-                                       text = text.replace( oldCitationString, 
newCitationString );
-                               });
-                       }
-
-                       // Update the textbox
                        textbox.val( text );
 
+                       // Update the citations
+                       reference.citations.forEach( function ( citation ) {
+                               citation.name = newName;
+                               citation.update();
+                       });
+
                        // Update the index and highlight the reference
                        text = textbox.val();
                        reference.index = text.indexOf( newString );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic71a580c64ffbe2c980be8d207b76db0132ef157
Gerrit-PatchSet: 1
Gerrit-Project: wikipedia/gadgets/ProveIt
Gerrit-Branch: master
Gerrit-Owner: Sophivorus <[email protected]>
Gerrit-Reviewer: Sophivorus <[email protected]>

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

Reply via email to