From ebe7205c63482a79940245f81fede4ea9906a894 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Thu, 23 Jun 2016 11:31:00 +0000 Subject: [PATCH] Edit stash: Support CodeEditor 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 | 1 - .../mediawiki.action.edit.stash.js | 25 +++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/resources/Resources.php b/resources/Resources.php index 90510fc125..e31e77e8c7 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1417,7 +1417,6 @@ return [ 'mediawiki.action.edit.styles', 'jquery.textSelection', 'jquery.byteLimit', - 'jquery.getAttrs', 'mediawiki.api', ], 'position' => 'top', diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.stash.js b/resources/src/mediawiki.action/mediawiki.action.edit.stash.js index 2069ac5005..2ae05dd6e5 100644 --- a/resources/src/mediawiki.action/mediawiki.action.edit.stash.js +++ b/resources/src/mediawiki.action/mediawiki.action.edit.stash.js @@ -13,7 +13,11 @@ $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. @@ -25,19 +29,19 @@ } 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() { -- 2.20.1