Remove listlevel internal state
This commit is contained in:
		
							parent
							
								
									5b61521e30
								
							
						
					
					
						commit
						f97c852c8a
					
				| @ -39,12 +39,6 @@ public interface MarkwonVisitor extends Visitor { | ||||
| 
 | ||||
|     boolean hasNext(@NonNull Node node); | ||||
| 
 | ||||
|     void incrementListLevel(); | ||||
| 
 | ||||
|     void decrementListLevel(); | ||||
| 
 | ||||
|     int listLevel(); | ||||
| 
 | ||||
|     void ensureNewLine(); | ||||
| 
 | ||||
|     void forceNewLine(); | ||||
| @ -52,4 +46,7 @@ public interface MarkwonVisitor extends Visitor { | ||||
|     int length(); | ||||
| 
 | ||||
|     void setSpans(int start, @Nullable Object spans); | ||||
| 
 | ||||
|     @Nullable | ||||
|     <N extends Node> NodeVisitor<N> nodeVisitor(@NonNull Class<N> node); | ||||
| } | ||||
|  | ||||
| @ -43,8 +43,6 @@ class MarkwonVisitorImpl implements MarkwonVisitor { | ||||
| 
 | ||||
|     private final SpannableBuilder builder = new SpannableBuilder(); | ||||
| 
 | ||||
|     private int listLevel; | ||||
| 
 | ||||
|     private MarkwonVisitorImpl( | ||||
|             @NonNull MarkwonConfiguration configuration, | ||||
|             @NonNull Map<Class<? extends Node>, NodeVisitor<? extends Node>> nodes) { | ||||
| @ -215,21 +213,6 @@ class MarkwonVisitorImpl implements MarkwonVisitor { | ||||
|         return node.getNext() != null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void incrementListLevel() { | ||||
|         listLevel += 1; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void decrementListLevel() { | ||||
|         listLevel -= 1; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public int listLevel() { | ||||
|         return listLevel; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void ensureNewLine() { | ||||
|         if (builder.length() > 0 | ||||
| @ -253,6 +236,13 @@ class MarkwonVisitorImpl implements MarkwonVisitor { | ||||
|         SpannableBuilder.setSpans(builder, spans, start, builder.length()); | ||||
|     } | ||||
| 
 | ||||
|     @Nullable | ||||
|     @Override | ||||
|     public <N extends Node> NodeVisitor<N> nodeVisitor(@NonNull Class<N> node) { | ||||
|         //noinspection unchecked | ||||
|         return (NodeVisitor<N>) nodes.get(node); | ||||
|     } | ||||
| 
 | ||||
|     static class BuilderImpl implements Builder { | ||||
| 
 | ||||
|         private final Map<Class<? extends Node>, NodeVisitor<? extends Node>> nodes = | ||||
|  | ||||
| @ -15,8 +15,6 @@ public class ListItemNodeVisitor implements MarkwonVisitor.NodeVisitor<ListItem> | ||||
| 
 | ||||
|         final int length = visitor.length(); | ||||
| 
 | ||||
|         visitor.incrementListLevel(); | ||||
| 
 | ||||
|         final Node parent = listItem.getParent(); | ||||
|         if (parent instanceof OrderedList) { | ||||
| 
 | ||||
| @ -33,14 +31,24 @@ public class ListItemNodeVisitor implements MarkwonVisitor.NodeVisitor<ListItem> | ||||
|         } else { | ||||
| 
 | ||||
|             visitor.visitChildren(listItem); | ||||
|             visitor.setSpans(length, visitor.factory().bulletListItem(visitor.theme(), visitor.listLevel() - 1)); | ||||
|             visitor.setSpans(length, visitor.factory().bulletListItem(visitor.theme(), listLevel(listItem))); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         visitor.decrementListLevel(); | ||||
| 
 | ||||
|         if (visitor.hasNext(listItem)) { | ||||
|             visitor.ensureNewLine(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private static int listLevel(@NonNull Node node) { | ||||
|         int level = 0; | ||||
|         Node parent = node.getParent(); | ||||
|         while (parent != null) { | ||||
|             if (parent instanceof ListItem) { | ||||
|                 level += 1; | ||||
|             } | ||||
|             parent = parent.getParent(); | ||||
|         } | ||||
|         return level; | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dimitry Ivanov
						Dimitry Ivanov