From 8423a1807162268d3f4b47b9ca7f5d4280b255ce Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 25 Nov 2021 20:59:18 +0300 Subject: Return early if not spoiler --- .../infinityforreddit/markdown/SpoilerParserPlugin.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java index a83df76a..bd926f7c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java @@ -51,15 +51,24 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); + + if(textView.getText().length() < 5) { + return; + } + SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); LinkedHashMap spoilers = parse(markdownStringBuilder); + if(spoilers.size() == 0) { + return; + } int offset = 2; for (Map.Entry entry : spoilers.entrySet()) { int spoilerStart = entry.getKey() - offset; int spoilerEnd = entry.getValue() - offset; + // Try not to set a spoiler span if it's inside a CodeSpan CodeSpan[] codeSpans = markdownStringBuilder.getSpans(spoilerStart, spoilerEnd, CodeSpan.class); CodeBlockSpan[] codeBlockSpans = markdownStringBuilder.getSpans(spoilerStart, spoilerEnd, CodeBlockSpan.class); @@ -108,7 +117,6 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { // Don't allow more than one new line after every non-blank line // Try not to care about recursing spoilers, we just want the outermost spoiler because // spoiler revealing-hiding breaks with recursing spoilers - // Try not to set a spoiler span if it's inside a CodeSpan private LinkedHashMap parse(SpannableStringBuilder markdown) { final int MAX_NEW_LINE = 1; var openSpoilerStack = new Stack(); -- cgit v1.2.3