From d0537df14d556d9410abaa950038c1042c3113ef Mon Sep 17 00:00:00 2001 From: Dimitry Date: Sat, 13 Jan 2018 21:06:34 +0300 Subject: [PATCH] Fix for ordered list items to be greater than theme block margin (#22) --- .../markwon/spans/OrderedListItemSpan.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/ru/noties/markwon/spans/OrderedListItemSpan.java b/library/src/main/java/ru/noties/markwon/spans/OrderedListItemSpan.java index 7c76f052..194f7676 100644 --- a/library/src/main/java/ru/noties/markwon/spans/OrderedListItemSpan.java +++ b/library/src/main/java/ru/noties/markwon/spans/OrderedListItemSpan.java @@ -11,6 +11,11 @@ public class OrderedListItemSpan implements LeadingMarginSpan { private final SpannableTheme theme; private final String number; + // we will use this variable to check if our order number text exceeds block margin, + // so we will use it instead of block margin + // @since 1.0.3 + private int margin; + public OrderedListItemSpan( @NonNull SpannableTheme theme, @NonNull String number @@ -21,7 +26,8 @@ public OrderedListItemSpan( @Override public int getLeadingMargin(boolean first) { - return theme.getBlockMargin(); + // @since 1.0.3 + return margin > 0 ? margin : theme.getBlockMargin(); } @Override @@ -35,9 +41,17 @@ public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int ba theme.applyListItemStyle(p); - final int width = theme.getBlockMargin(); final int numberWidth = (int) (p.measureText(number) + .5F); + // @since 1.0.3 + int width = theme.getBlockMargin(); + if (numberWidth > width) { + width = numberWidth; + margin = numberWidth; + } else { + margin = 0; + } + final int left; if (dir > 0) { left = x + (width * dir) - numberWidth;