diff --git a/modules/dt.ui.ReplyWidget.js b/modules/dt.ui.ReplyWidget.js index cb9d77e76..ace9ace33 100644 --- a/modules/dt.ui.ReplyWidget.js +++ b/modules/dt.ui.ReplyWidget.js @@ -552,7 +552,7 @@ ReplyWidget.prototype.onInputChange = function () { * @return {jQuery.Promise} Promise resolved when we're done */ ReplyWidget.prototype.preparePreview = function ( wikitext ) { - var parsePromise, widget, title, indent; + var parsePromise, widget, title, indent, signature; if ( this.getMode() !== 'source' ) { return $.Deferred().resolve().promise(); @@ -588,8 +588,13 @@ ReplyWidget.prototype.preparePreview = function ( wikitext ) { if ( !modifier.isWikitextSigned( wikitext ) ) { // Add signature. + signature = mw.msg( 'discussiontools-signature-prefix' ) + '~~~~'; // Drop opacity of signature in preview to make message body preview clearer. - wikitext = wikitext + '' + mw.msg( 'discussiontools-signature-prefix' ) + '~~~~'; + // Extract any leading spaces outside the markup to ensure accurate previews. + signature = signature.replace( /^( *)(.+)$/, function ( _, leadingSpaces, sig ) { + return leadingSpaces + '' + sig + ''; + } ); + wikitext += signature; } if ( title ) { wikitext = '== ' + title + ' ==\n' + wikitext;