diff options
author | scria1000 <91804886+scria1000@users.noreply.github.com> | 2021-11-25 17:59:18 +0000 |
---|---|---|
committer | scria1000 <91804886+scria1000@users.noreply.github.com> | 2021-11-25 17:59:18 +0000 |
commit | 8423a1807162268d3f4b47b9ca7f5d4280b255ce (patch) | |
tree | 397d67680db35cfdd8015ade6256640aa7928e8f /app/src/main/java | |
parent | e481980480bc5666edd671a06a71078525824bac (diff) | |
download | infinity-for-reddit-8423a1807162268d3f4b47b9ca7f5d4280b255ce.tar infinity-for-reddit-8423a1807162268d3f4b47b9ca7f5d4280b255ce.tar.gz infinity-for-reddit-8423a1807162268d3f4b47b9ca7f5d4280b255ce.tar.bz2 infinity-for-reddit-8423a1807162268d3f4b47b9ca7f5d4280b255ce.tar.lz infinity-for-reddit-8423a1807162268d3f4b47b9ca7f5d4280b255ce.tar.xz infinity-for-reddit-8423a1807162268d3f4b47b9ca7f5d4280b255ce.tar.zst infinity-for-reddit-8423a1807162268d3f4b47b9ca7f5d4280b255ce.zip |
Return early if not spoiler
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java | 10 |
1 files changed, 9 insertions, 1 deletions
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<Integer, Integer> spoilers = parse(markdownStringBuilder); + if(spoilers.size() == 0) { + return; + } int offset = 2; for (Map.Entry<Integer, Integer> 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<Integer, Integer> parse(SpannableStringBuilder markdown) { final int MAX_NEW_LINE = 1; var openSpoilerStack = new Stack<Integer>(); |