From 57b0ae8b858d74e259570afb020daa6c4ac96e06 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 8 Mar 2023 20:41:41 -0500 Subject: [PATCH] Move quote code to quote helper --- .../eu/siacs/conversations/ui/util/QuoteHelper.java | 13 ++++++++++++- .../siacs/conversations/ui/widget/EditMessage.java | 9 +-------- 2 files changed, 13 insertions(+), 9 deletions(-) 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 c2a69e6074f9506232f4a47ad2156ddc8e45cbfa..883c5507a9dae04016c4dd71a4822cffbaa812f1 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/QuoteHelper.java +++ b/src/main/java/eu/siacs/conversations/ui/util/QuoteHelper.java @@ -103,4 +103,15 @@ public class QuoteHelper { } return text; } -} \ No newline at end of file + + public static String quote(String text) { + text = replaceAltQuoteCharsInText(text); + return text + // first replace all '>' at the beginning of the line with nice and tidy '>>' + // for nested quoting + .replaceAll("(^|\n)(" + QUOTE_CHAR + ")", "$1$2$2") + // then find all other lines and have them start with a '> ' + .replaceAll("(^|\n)(?!" + QUOTE_CHAR + ")(.*)", "$1> $2") + ; + } +} 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 455c3ba440589cebdbb19f2ee7f318e4cf21a6ec..bcacb3341db388d6d4f7e8cf41a6003b65a74129 100644 --- a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java +++ b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java @@ -144,14 +144,7 @@ public class EditMessage extends AppCompatEditText { } public void insertAsQuote(String text) { - text = QuoteHelper.replaceAltQuoteCharsInText(text); - 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") - ; + text = QuoteHelper.quote(text); Editable editable = getEditableText(); int position = getSelectionEnd(); if (position == -1) position = editable.length();