From 1a52f06daf4e2cb26f3f213e8e66209bc48eb03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sat, 6 Mar 2021 19:16:21 +0100 Subject: [PATCH] Tweak signature formatting in previews for more accurate results When posting a new topic, if your comment ends with a template that has trailing line breaks, the signature will be added as a preformatted text (which is arguably a bug: T255741). Preview, however, did not reflect this bug, because of the markup added to fade out the automatic signature. Change-Id: I062b01a035e22edfca752a49c5e2433b3f7fb4f6 --- modules/dt.ui.ReplyWidget.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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;