preserve new lines when quoting. fixes #3876

This commit is contained in:
Millesimus 2022-09-05 12:17:57 +02:00 committed by Daniel Gultsch
parent 22f4129262
commit 562ffd2003
3 changed files with 12 additions and 10 deletions

View file

@ -84,13 +84,13 @@ public class QuoteHelper {
if (isPositionQuoteStart(line, 0)) { if (isPositionQuoteStart(line, 0)) {
int nestingDepth = 1; int nestingDepth = 1;
for (int i = 1; i < line.length(); i++) { for (int i = 1; i < line.length(); i++) {
if (isPositionQuoteStart(line, i)) { if (isPositionQuoteCharacter(line, i)) {
nestingDepth++; nestingDepth++;
} } else if (line.charAt(i) != ' ') {
if (nestingDepth > (Config.QUOTING_MAX_DEPTH - 1)) { break;
return true;
} }
} }
return nestingDepth >= (Config.QUOTING_MAX_DEPTH);
} }
return false; return false;
} }

View file

@ -145,7 +145,13 @@ public class EditMessage extends AppCompatEditText {
public void insertAsQuote(String text) { public void insertAsQuote(String text) {
text = QuoteHelper.replaceAltQuoteCharsInText(text); text = QuoteHelper.replaceAltQuoteCharsInText(text);
text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)(" + QuoteHelper.QUOTE_CHAR + ")", "$1$2$2").replaceAll("(^|\n)([^" + QuoteHelper.QUOTE_CHAR + "])", "$1> $2").replaceAll("\n$", ""); text = text
// first replace all '>' at the beginning of the line with nice and tidy '>>'
// for nested quoting
.replaceAll("(^|\n)(" + QuoteHelper.QUOTE_CHAR + ")", "$1$2$2")
// then find all other lines and have them start with a '> '
.replaceAll("(^|\n)(?!" + QuoteHelper.QUOTE_CHAR + ")(.*)", "$1> $2")
;
Editable editable = getEditableText(); Editable editable = getEditableText();
int position = getSelectionEnd(); int position = getSelectionEnd();
if (position == -1) position = editable.length(); if (position == -1) position = editable.length();

View file

@ -66,11 +66,7 @@ public class MessageUtils {
body = message.getMergedBody().toString(); body = message.getMergedBody().toString();
} }
for (String line : body.split("\n")) { for (String line : body.split("\n")) {
if (line.length() <= 0) { if (!(line.length() <= 0) && QuoteHelper.isNestedTooDeeply(line)) {
continue;
}
final char c = line.charAt(0);
if (QuoteHelper.isNestedTooDeeply(line)) {
continue; continue;
} }
if (builder.length() != 0) { if (builder.length() != 0) {