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

Change subject: Move restoreEditSection() to mw.Target
......................................................................


Move restoreEditSection() to mw.Target

It can be reused in mw.ViewPageTarget and mw.MobileViewTarget.

Also, check if this.section is undefined instead of not null and update
docs. restoreEditSection() does not accept any arguments.

Change-Id: Ibbcf4cb936a89d3ae77bb61ee97b8ad00a8d8a53
---
M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
M modules/ve-mw/init/ve.init.mw.Target.js
2 files changed, 50 insertions(+), 50 deletions(-)

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



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 4e9392a..4ffc25d 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
@@ -47,7 +47,7 @@
        this.actFromPopState = false;
        this.scrollTop = null;
        this.currentUri = currentUri;
-       this.section = currentUri.query.vesection || null;
+       this.section = currentUri.query.vesection;
        this.initialEditSummary = '';
        this.namespaceName = mw.config.get( 'wgCanonicalNamespace' );
        this.viewUri = new mw.Uri( mw.util.getUrl( this.pageName ) );
@@ -1424,55 +1424,6 @@
  */
 ve.init.mw.ViewPageTarget.prototype.saveEditSection = function ( heading ) {
        this.section = this.getEditSection( heading );
-};
-
-/**
- * Move the cursor in the editor to a given section.
- *
- * @method
- * @param {number} section Section to move cursor to
- */
-ve.init.mw.ViewPageTarget.prototype.restoreEditSection = function () {
-       if ( this.section !== null ) {
-               var offset, offsetNode, nextNode,
-                       target = this,
-                       surfaceView = this.surface.getView(),
-                       surfaceModel = surfaceView.getModel(),
-                       $section = this.$document.find( 'h1, h2, h3, h4, h5, 
h6' ).eq( this.section - 1 ),
-                       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;
-                       while ( offsetNode instanceof ve.ce.HeadingNode && 
offsetNode.getModel().getAttribute( 'level' ) > lastHeadingLevel ) {
-                               lastHeadingLevel = 
offsetNode.getModel().getAttribute( 'level' );
-                               // Next sibling
-                               nextNode = 
offsetNode.parent.children[ve.indexOf( offsetNode, offsetNode.parent.children ) 
+ 1];
-                               if ( !nextNode ) {
-                                       break;
-                               }
-                               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.section = null;
-       }
 };
 
 /**
diff --git a/modules/ve-mw/init/ve.init.mw.Target.js 
b/modules/ve-mw/init/ve.init.mw.Target.js
index 8f20d15..0324958 100644
--- a/modules/ve-mw/init/ve.init.mw.Target.js
+++ b/modules/ve-mw/init/ve.init.mw.Target.js
@@ -1250,3 +1250,52 @@
                        viewPage.emit( 'sanityCheckComplete' );
                } );
 };
+
+/**
+ * Move the cursor in the editor to section specified by this.section.
+ * Do nothing if this.section is undefined.
+ *
+ * @method
+ */
+ve.init.mw.Target.prototype.restoreEditSection = function () {
+       if ( this.section !== undefined ) {
+               var offset, offsetNode, nextNode,
+                       target = this,
+                       surfaceView = this.surface.getView(),
+                       surfaceModel = surfaceView.getModel(),
+                       $section = this.$document.find( 'h1, h2, h3, h4, h5, 
h6' ).eq( this.section - 1 ),
+                       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;
+                       while ( offsetNode instanceof ve.ce.HeadingNode && 
offsetNode.getModel().getAttribute( 'level' ) > lastHeadingLevel ) {
+                               lastHeadingLevel = 
offsetNode.getModel().getAttribute( 'level' );
+                               // Next sibling
+                               nextNode = 
offsetNode.parent.children[ve.indexOf( offsetNode, offsetNode.parent.children ) 
+ 1];
+                               if ( !nextNode ) {
+                                       break;
+                               }
+                               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.section = undefined;
+       }
+};

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibbcf4cb936a89d3ae77bb61ee97b8ad00a8d8a53
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: JGonera <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to