Esanders has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/327330 )

Change subject: Extra section title for edit summary in source mode
......................................................................

Extra section title for edit summary in source mode

Bug: T153245
Change-Id: I3b3465f269831152fd7a820027f44bfaada067a8
---
M modules/ve-mw/init/ve.init.mw.ArticleTarget.js
1 file changed, 26 insertions(+), 12 deletions(-)


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

diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js 
b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
index 4ac11c3..a68c233 100644
--- a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
+++ b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
@@ -1855,22 +1855,36 @@
  * @method
  */
 ve.init.mw.ArticleTarget.prototype.restoreEditSection = function () {
-       var surface = this.getSurface(),
+       var headingText,
+               surface = this.getSurface(),
+               mode = surface.getMode(),
                surfaceView, $documentNode, $section, headingNode;
 
-       if ( surface.getMode() === 'visual' && this.section !== null && 
this.section > 0 ) {
-               surfaceView = surface.getView();
-               $documentNode = 
surfaceView.getDocument().getDocumentNode().$element;
-               $section = $documentNode.find( 'h1, h2, h3, h4, h5, h6' ).eq( 
this.section - 1 );
-               headingNode = $section.data( 'view' );
+       if ( this.section !== null && this.section !== 'new' && this.section 
!== 0 ) {
+               if ( mode === 'visual' ) {
+                       surfaceView = surface.getView();
+                       $documentNode = 
surfaceView.getDocument().getDocumentNode().$element;
+                       $section = $documentNode.find( 'h1, h2, h3, h4, h5, h6' 
).eq( this.section - 1 );
+                       headingNode = $section.data( 'view' );
 
-               if ( $section.length && new mw.Uri().query.summary === 
undefined ) {
-                       this.initialEditSummary = '/* ' +
-                               ve.graphemeSafeSubstring( $section.text(), 0, 
244 ) + ' */ ';
+                       if ( $section.length && new mw.Uri().query.summary === 
undefined ) {
+                               headingText = $section.text();
+                       }
+
+                       if ( headingNode ) {
+                               this.goToHeading( headingNode );
+                       }
+               } else if ( mode === 'source' ) {
+                       headingText = 
surface.getModel().getDocument().data.getText(
+                               false,
+                               
surface.getModel().getDocument().getDocumentNode().children[ 0 ].getRange()
+                       ).replace( /^\s*=+\s*(.*?)\s*=+\s*$/, '$1' );
                }
-
-               if ( headingNode ) {
-                       this.goToHeading( headingNode );
+               if ( headingText ) {
+                       this.initialEditSummary =
+                               '/* ' +
+                               ve.graphemeSafeSubstring( headingText, 0, 244 ) 
+
+                               ' */ ';
                }
        }
 };

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

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

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

Reply via email to