Remove increment/decrement blockIndent from visitor
This commit is contained in:
		
							parent
							
								
									19cd94febb
								
							
						
					
					
						commit
						5b61521e30
					
				| @ -8,6 +8,7 @@ import android.support.annotation.ColorInt; | ||||
| import android.support.annotation.NonNull; | ||||
| import android.util.TypedValue; | ||||
| 
 | ||||
| import org.commonmark.node.Node; | ||||
| import org.commonmark.parser.Parser; | ||||
| 
 | ||||
| import ru.noties.markwon.AbstractMarkwonPlugin; | ||||
| @ -70,9 +71,7 @@ public class TaskListPlugin extends AbstractMarkwonPlugin { | ||||
| 
 | ||||
|                         visitor.ensureNewLine(); | ||||
| 
 | ||||
|                         visitor.incrementBlockIndent(); | ||||
|                         visitor.visitChildren(taskListBlock); | ||||
|                         visitor.decrementBlockIndent(); | ||||
| 
 | ||||
|                         if (visitor.hasNext(taskListBlock)) { | ||||
|                             visitor.ensureNewLine(); | ||||
| @ -86,20 +85,16 @@ public class TaskListPlugin extends AbstractMarkwonPlugin { | ||||
| 
 | ||||
|                         final int length = visitor.length(); | ||||
| 
 | ||||
|                         final int indent = visitor.blockIndent(); | ||||
|                         visitor.blockIntent(indent + taskListItem.indent()); | ||||
|                         visitor.visitChildren(taskListItem); | ||||
|                         visitor.setSpans(length, new TaskListSpan( | ||||
|                                 visitor.theme(), | ||||
|                                 drawable, | ||||
|                                 visitor.blockIndent(), | ||||
|                                 indent(taskListItem) + taskListItem.indent(), | ||||
|                                 taskListItem.done())); | ||||
| 
 | ||||
|                         if (visitor.hasNext(taskListItem)) { | ||||
|                             visitor.ensureNewLine(); | ||||
|                         } | ||||
| 
 | ||||
|                         visitor.blockIntent(indent); | ||||
|                     } | ||||
|                 }); | ||||
|     } | ||||
| @ -114,4 +109,17 @@ public class TaskListPlugin extends AbstractMarkwonPlugin { | ||||
|             typedArray.recycle(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private static int indent(@NonNull Node node) { | ||||
|         int indent = 0; | ||||
|         Node parent = node.getParent(); | ||||
|         if (parent != null) { | ||||
|             parent = parent.getParent(); | ||||
|             while (parent != null) { | ||||
|                 indent += 1; | ||||
|                 parent = parent.getParent(); | ||||
|             } | ||||
|         } | ||||
|         return indent; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -19,10 +19,6 @@ public interface MarkwonVisitor extends Visitor { | ||||
|         @NonNull | ||||
|         <N extends Node> Builder on(@NonNull Class<N> node, @Nullable NodeVisitor<? super N> nodeVisitor); | ||||
| 
 | ||||
|         // to obtain currently registered one | ||||
|         @Nullable | ||||
|         <N extends Node> NodeVisitor<N> registeredVisitor(@NonNull Class<N> node); | ||||
| 
 | ||||
|         @NonNull | ||||
|         MarkwonVisitor build(@NonNull MarkwonConfiguration configuration); | ||||
|     } | ||||
| @ -43,14 +39,6 @@ public interface MarkwonVisitor extends Visitor { | ||||
| 
 | ||||
|     boolean hasNext(@NonNull Node node); | ||||
| 
 | ||||
|     void incrementBlockIndent(); | ||||
| 
 | ||||
|     void decrementBlockIndent(); | ||||
| 
 | ||||
|     void blockIntent(int blockIndent); | ||||
| 
 | ||||
|     int blockIndent(); | ||||
| 
 | ||||
|     void incrementListLevel(); | ||||
| 
 | ||||
|     void decrementListLevel(); | ||||
|  | ||||
| @ -43,7 +43,6 @@ class MarkwonVisitorImpl implements MarkwonVisitor { | ||||
| 
 | ||||
|     private final SpannableBuilder builder = new SpannableBuilder(); | ||||
| 
 | ||||
|     private int blockQuoteIndent; | ||||
|     private int listLevel; | ||||
| 
 | ||||
|     private MarkwonVisitorImpl( | ||||
| @ -216,26 +215,6 @@ class MarkwonVisitorImpl implements MarkwonVisitor { | ||||
|         return node.getNext() != null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void incrementBlockIndent() { | ||||
|         blockQuoteIndent += 1; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void decrementBlockIndent() { | ||||
|         blockQuoteIndent -= 1; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void blockIntent(int blockIndent) { | ||||
|         this.blockQuoteIndent = blockIndent; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public int blockIndent() { | ||||
|         return blockQuoteIndent; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void incrementListLevel() { | ||||
|         listLevel += 1; | ||||
| @ -292,13 +271,6 @@ class MarkwonVisitorImpl implements MarkwonVisitor { | ||||
|             return this; | ||||
|         } | ||||
| 
 | ||||
|         @Nullable | ||||
|         @Override | ||||
|         public <N extends Node> NodeVisitor<N> registeredVisitor(@NonNull Class<N> node) { | ||||
|             //noinspection unchecked | ||||
|             return (NodeVisitor<N>) nodes.get(node); | ||||
|         } | ||||
| 
 | ||||
|         @NonNull | ||||
|         @Override | ||||
|         public MarkwonVisitor build(@NonNull MarkwonConfiguration configuration) { | ||||
|  | ||||
| @ -13,10 +13,9 @@ public class BlockQuoteNodeVisitor implements MarkwonVisitor.NodeVisitor<BlockQu | ||||
|         visitor.ensureNewLine(); | ||||
| 
 | ||||
|         final int length = visitor.length(); | ||||
|         visitor.incrementBlockIndent(); | ||||
| 
 | ||||
|         visitor.visitChildren(blockQuote); | ||||
|         visitor.setSpans(length, visitor.factory().blockQuote(visitor.theme())); | ||||
|         visitor.decrementBlockIndent(); | ||||
| 
 | ||||
|         if (visitor.hasNext(blockQuote)) { | ||||
|             visitor.ensureNewLine(); | ||||
|  | ||||
| @ -15,7 +15,6 @@ public class ListItemNodeVisitor implements MarkwonVisitor.NodeVisitor<ListItem> | ||||
| 
 | ||||
|         final int length = visitor.length(); | ||||
| 
 | ||||
|         visitor.incrementBlockIndent(); | ||||
|         visitor.incrementListLevel(); | ||||
| 
 | ||||
|         final Node parent = listItem.getParent(); | ||||
| @ -38,7 +37,6 @@ public class ListItemNodeVisitor implements MarkwonVisitor.NodeVisitor<ListItem> | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         visitor.decrementBlockIndent(); | ||||
|         visitor.decrementListLevel(); | ||||
| 
 | ||||
|         if (visitor.hasNext(listItem)) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dimitry Ivanov
						Dimitry Ivanov