Catrope has uploaded a new change for review.

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


Change subject: Consolidate edit section handling code in ViewPageTarget
......................................................................

Consolidate edit section handling code in ViewPageTarget

Move generation of initial edit summary from setupSaveDialog() to
restoreEditSection().

This allows us to get rid of the properties tracking whether both
halves of the edit section handling had happened, because they're
now in the same method.

Change-Id: I06a9c5cf5c752acea8a2ac25d0ffb6ac61cfe986
---
M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
1 file changed, 9 insertions(+), 40 deletions(-)


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

diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js 
b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
index 13658a6..893761a 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
@@ -51,8 +51,6 @@
        this.scrollTop = null;
        this.currentUri = currentUri;
        this.section = currentUri.query.vesection || null;
-       this.sectionPositionRestored = false;
-       this.sectionTitleRestored = false;
        this.namespaceName = mw.config.get( 'wgCanonicalNamespace' );
        this.viewUri = new mw.Uri( mw.util.getUrl( this.pageName ) );
        this.veEditUri = this.viewUri.clone().extend( { 'veaction': 'edit' } );
@@ -1210,19 +1208,7 @@
  * @method
  */
 ve.init.mw.ViewPageTarget.prototype.setupSaveDialog = function () {
-       var sectionTitle = '';
-
        this.saveDialog = this.surface.getDialogs().getWindow( 'mwSave' );
-
-       if ( this.section ) {
-               sectionTitle = this.$document.find( 'h1, h2, h3, h4, h5, h6' 
).eq( this.section - 1 ).text();
-               sectionTitle = '/* ' + ve.graphemeSafeSubstring( sectionTitle, 
0, 244 ) + ' */ ';
-               this.saveDialog.setEditSummary( sectionTitle );
-               this.sectionTitleRestored = true;
-               if ( this.sectionPositionRestored ) {
-                       this.onSectionRestored();
-               }
-       }
        // Connect to save dialog
        this.saveDialog.connect( this, {
                'save': 'onSaveDialogSave',
@@ -1230,7 +1216,8 @@
                'resolve': 'onSaveDialogResolveConflict',
                'close': 'onSaveDialogClose'
        } );
-       // Setup checkboxes
+       // Setup edit summary and checkboxes
+       this.saveDialog.setEditSummary( this.initialEditSummary );
        this.saveDialog.setupCheckboxes( ve.getObjectValues( this.checkboxes 
).join( '\n' ) );
 };
 
@@ -1592,6 +1579,11 @@
                        headingNode = $section.data( 'view' ),
                        lastHeadingLevel = -1;
 
+               if ( $section.length ) {
+                       this.initialEditSummary = '/* ' +
+                               ve.graphemeSafeSubstring( $section.text(), 0, 
244 ) + ' */ ';
+               }
+
                if ( headingNode ) {
                        // Find next sibling which isn't a heading
                        offsetNode = headingNode;
@@ -1604,32 +1596,9 @@
                                }
                                offsetNode = nextNode;
                        }
-                       offset = 
surfaceModel.getDocument().data.getNearestContentOffset(
-                               offsetNode.getModel().getOffset(), 1
-                       );
-                       surfaceModel.setSelection( new ve.Range( offset ) );
-                       // Scroll to heading:
-                       // Wait for toolbar to animate in so we can account for 
its height
-                       setTimeout( function () {
-                               var $window = $( OO.ui.Element.getWindow( 
target.$element ) );
-                               $window.scrollTop( 
headingNode.$element.offset().top - target.toolbar.$element.height() );
-                       }, 200 );
-               }
-
-               this.sectionPositionRestored = true;
-               if ( this.sectionTitleRestored ) {
-                       this.onSectionRestored();
-               }
+               } );
+               this.section = null;
        }
-};
-
-/**
- * Handle restoration of section editing position and title
- */
-ve.init.mw.ViewPageTarget.prototype.onSectionRestored = function () {
-       this.section = null;
-       this.sectionPositionRestored = false;
-       this.sectionTitleRestored = false;
 };
 
 /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I06a9c5cf5c752acea8a2ac25d0ffb6ac61cfe986
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

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

Reply via email to