diff --git a/src/main/java/eu/siacs/conversations/ui/util/QuoteHelper.java b/src/main/java/eu/siacs/conversations/ui/util/QuoteHelper.java index cf49be767..c2a69e607 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/QuoteHelper.java +++ b/src/main/java/eu/siacs/conversations/ui/util/QuoteHelper.java @@ -84,13 +84,13 @@ public class QuoteHelper { if (isPositionQuoteStart(line, 0)) { int nestingDepth = 1; for (int i = 1; i < line.length(); i++) { - if (isPositionQuoteStart(line, i)) { + if (isPositionQuoteCharacter(line, i)) { nestingDepth++; - } - if (nestingDepth > (Config.QUOTING_MAX_DEPTH - 1)) { - return true; + } else if (line.charAt(i) != ' ') { + break; } } + return nestingDepth >= (Config.QUOTING_MAX_DEPTH); } return false; } diff --git a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java index e890e5984..455c3ba44 100644 --- a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java +++ b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java @@ -145,7 +145,13 @@ public class EditMessage extends AppCompatEditText { public void insertAsQuote(String 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(); int position = getSelectionEnd(); if (position == -1) position = editable.length(); diff --git a/src/main/java/eu/siacs/conversations/utils/MessageUtils.java b/src/main/java/eu/siacs/conversations/utils/MessageUtils.java index 0a11cd720..9687a7b14 100644 --- a/src/main/java/eu/siacs/conversations/utils/MessageUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/MessageUtils.java @@ -66,11 +66,7 @@ public class MessageUtils { body = message.getMergedBody().toString(); } for (String line : body.split("\n")) { - if (line.length() <= 0) { - continue; - } - final char c = line.charAt(0); - if (QuoteHelper.isNestedTooDeeply(line)) { + if (!(line.length() <= 0) && QuoteHelper.isNestedTooDeeply(line)) { continue; } if (builder.length() != 0) {