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.
This commit is contained in:
Ben Hadley-Evans 2015-04-07 17:47:04 +01:00
parent 13e97a0b77
commit 895e0261ed
1 changed files with 17 additions and 9 deletions

View File

@ -1551,12 +1551,12 @@
// Don't show the fallback text if more than one line is selected, // Don't show the fallback text if more than one line is selected,
// it's probably a break between paragraphs. // it's probably a break between paragraphs.
if (lines.length > 1) { if (lines.length > 1) {
fallbackText = "" fallbackText = "";
} }
for(var i=0; i<lines.length; i++) { for(var i=0; i<lines.length; i++) {
// Split before, selection and after up. // Split before, selection and after up.
var lineMatch = lines[i].match(/^(\**)(.*?)(\**)$/); var lineMatch = lines[i].match(/^(\s*\**)(.*?)(\**\s*)$/);
var newChunk = new Chunks(); var newChunk = new Chunks();
newChunk.before = lineMatch[1]; newChunk.before = lineMatch[1];
@ -1564,8 +1564,16 @@
newChunk.after = lineMatch[3]; newChunk.after = lineMatch[3];
this.doSurroundLine(newChunk, postProcessing, nStars, fallbackText); this.doSurroundLine(newChunk, postProcessing, nStars, fallbackText);
if (lines.length > 1) {
lines[i] = newChunk.before + newChunk.selection + newChunk.after; 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"); realChunk.selection = lines.join("\n");
}; };