diff --git a/exec/SlyEdit_Misc.js b/exec/SlyEdit_Misc.js index 1ab7a3f35c68b1699805cc6788e10cdd3e14782b..12dc07cdbe672e2d1795df65098c556c0e44a7d4 100644 --- a/exec/SlyEdit_Misc.js +++ b/exec/SlyEdit_Misc.js @@ -2906,10 +2906,10 @@ function wrapTextLinesForQuoting(pTextLines, pQuotePrefix, pIndentQuoteLines, pT // Get the length of the current line (if it needs wrapping, then wrap it & get the // length of the last line after wrapping), so that if that length is short, we might // put a CRLF at the end to signify the end of the paragraph/section - var lineLength = 0; + var lineLastLength = 0; var currentLineScreenLen = console.strlen(pTextLines[textLineIdx]); if (currentLineScreenLen < console.screen_columns - 1) - lineLength = currentLineScreenLen; + lineLastLength = currentLineScreenLen; else { var currentLine = pTextLines[textLineIdx]; @@ -2917,14 +2917,17 @@ function wrapTextLinesForQuoting(pTextLines, pQuotePrefix, pIndentQuoteLines, pT currentLine = currentLine.trim(); var paragraphLines = lfexpand(word_wrap(currentLine, console.screen_columns-1, null, true)).split("\r\n"); paragraphLines.pop(); // There will be an extra empty line at the end; remove it - lineLength = console.strlen(paragraphLines[paragraphLines.length-1]); + if (paragraphLines.length > 0) + lineLastLength = console.strlen(paragraphLines[paragraphLines.length-1]); } // Put a CRLF at the end in certain conditions if (nextLineIsOriginOrTearLine) sectionText += "\r\n"; // Append a CRLF if the line isn't blank and its length is less than 85% of the user's terminal width //else if (numLinesInSection > 1 && !nextLineIsBlank && console.strlen(pTextLines[textLineIdx]) < Math.floor(console.screen_columns * 0.85)) - else if (numLinesInSection > 1 && !nextLineIsBlank && lineLength < Math.floor(console.screen_columns * 0.85)) + // ..and also if the text line is originally over 120 characters (a bit arbitrary, but if a line is that long, then + // it's probably its own paragraph + else if (numLinesInSection > 1 && !nextLineIsBlank && lineLastLength < Math.floor(console.screen_columns * 0.85) && console.strlen(pTextLines[textLineIdx]) > 120) sectionText += "\r\n"; else if (nextLineIsBlank) sectionText += "\r\n";