Edit stash: Support CodeEditor
authorFomafix <fomafix@googlemail.com>
Thu, 23 Jun 2016 11:31:00 +0000 (11:31 +0000)
committerLegoktm <legoktm.wikipedia@gmail.com>
Fri, 24 Jun 2016 12:36:06 +0000 (12:36 +0000)
Use .textSelection( 'getContents' ) instead of .val() for '#wpTextbox1' and '#wpSummary'.

Then the normalization of line endings and dependency on 'jquery.getAttrs' is not necessary.

Bug: T137861
Change-Id: I26f7021a2a02cf719c9e5f44787b95cfc3239959

resources/Resources.php
resources/src/mediawiki.action/mediawiki.action.edit.stash.js

index 90510fc..e31e77e 100644 (file)
@@ -1417,7 +1417,6 @@ return [
                        'mediawiki.action.edit.styles',
                        'jquery.textSelection',
                        'jquery.byteLimit',
-                       'jquery.getAttrs',
                        'mediawiki.api',
                ],
                'position' => 'top',
index 2069ac5..2ae05dd 100644 (file)
                        $form = $( '#editform' ),
                        $text = $form.find( '#wpTextbox1' ),
                        $summary = $form.find( '#wpSummary' ),
-                       data = {},
+                       section = $form.find( '#wpSection' ).val(),
+                       model = $form.find( '#model' ).val(),
+                       format = $form.find( '#format' ).val(),
+                       revId = $form.find( '#parentRevId' ).val(),
+                       lastText = $text.textSelection( 'getContents' ),
                        timer = null;
 
                // Send a request to stash the edit to the API.
                        }
 
                        api.getToken( 'csrf' ).then( function ( token ) {
-                               data = $form.serializeObject();
+                               lastText = $text.textSelection( 'getContents' );
 
                                pending = api.post( {
                                        action: 'stashedit',
                                        token: token,
                                        title: mw.config.get( 'wgPageName' ),
-                                       section: data.wpSection,
+                                       section: section,
                                        sectiontitle: '',
-                                       text: data.wpTextbox1,
-                                       summary: data.wpSummary,
-                                       contentmodel: data.model,
-                                       contentformat: data.format,
-                                       baserevid: data.parentRevId
+                                       text: lastText,
+                                       summary: $summary.textSelection( 'getContents' ),
+                                       contentmodel: model,
+                                       contentformat: format,
+                                       baserevid: revId
                                } );
                        } );
                }
@@ -45,9 +49,8 @@
                // Check if edit body text changed since the last stashEdit() call or if no edit
                // stash calls have yet been made
                function isChanged() {
-                       // Normalize line endings to CRLF, like $.fn.serializeObject does.
-                       var newText = $text.val().replace( /\r?\n/g, '\r\n' );
-                       return newText !== data.wpTextbox1;
+                       var newText = $text.textSelection( 'getContents' );
+                       return newText !== lastText;
                }
 
                function onEditorIdle() {