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