From 895e0261edf64ec8f359a16824d7a9e36ee60a15 Mon Sep 17 00:00:00 2001 From: Ben Hadley-Evans Date: Tue, 7 Apr 2015 17:47:04 +0100 Subject: [PATCH] Fix italics/bold WYSIWYG bug with nothing highlighted. This bug was reported here: https://meta.discourse.org/t/ctrl-b-selects-asterisks/27215 - It was something I broke whilst writing PR3288. The fix checks if it is a multiline selection, if it is not (which includes blank selections) it will leave the asterisks unhighlighted. Also fix a bug where asterisks would not be stripped if there was whitespace at the beginning of a line in a multiline selection. Also fix styling issues I missed last time so that it matches the rest of the document. Specifically, 4 character tabs and spaces after "if"s. --- .../discourse/lib/Markdown.Editor.js | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/Markdown.Editor.js b/app/assets/javascripts/discourse/lib/Markdown.Editor.js index 58e3929f8c5..7c6ef13587b 100644 --- a/app/assets/javascripts/discourse/lib/Markdown.Editor.js +++ b/app/assets/javascripts/discourse/lib/Markdown.Editor.js @@ -1550,13 +1550,13 @@ // Don't show the fallback text if more than one line is selected, // it's probably a break between paragraphs. - if(lines.length > 1) { - fallbackText = "" + if (lines.length > 1) { + fallbackText = ""; } for(var i=0; i 1) { + lines[i] = newChunk.before + newChunk.selection + newChunk.after; + } else { + realChunk.startTag = newChunk.before; + realChunk.endTag = newChunk.after; + lines[i] = newChunk.selection; + } } + realChunk.selection = lines.join("\n"); }; @@ -1591,11 +1599,11 @@ } // Only operate if it's not a blank line - if(chunk.selection) { - // Add the true markup. - var markup = nStars === 1 ? "*" : "**"; - chunk.before = chunk.before + markup; - chunk.after = markup + chunk.after; + if (chunk.selection) { + // Add the true markup. + var markup = nStars === 1 ? "*" : "**"; + chunk.before = chunk.before + markup; + chunk.after = markup + chunk.after; } } };