Refactor some indent logic

pull/14/head
Sam Bosley 12 years ago
parent 8ec79a2eb9
commit 64e2b7bc14

@ -150,8 +150,7 @@ public abstract class NewOrderedListUpdater<LIST> {
siblings.remove(index); siblings.remove(index);
node.parent = newParent; node.parent = newParent;
newParent.children.add(node); newParent.children.add(node);
node.indent = newParent.indent + 1; setNodeIndent(node, newParent.indent + 1);
adjustDescendantsIndent(node, node.indent);
} else if (delta < 0) { } else if (delta < 0) {
if (parent == treeRoot) // Can't deindent a top level item if (parent == treeRoot) // Can't deindent a top level item
return; return;
@ -166,12 +165,16 @@ public abstract class NewOrderedListUpdater<LIST> {
int insertAfter = newSiblings.indexOf(parent); int insertAfter = newSiblings.indexOf(parent);
siblings.remove(index); siblings.remove(index);
node.parent = newParent; node.parent = newParent;
node.indent = newParent.indent + 1; setNodeIndent(node, newParent.indent + 1);
adjustDescendantsIndent(node, node.indent);
newSiblings.add(insertAfter + 1, node); newSiblings.add(insertAfter + 1, node);
} }
} }
private void setNodeIndent(Node node, int indent) {
node.indent = indent;
adjustDescendantsIndent(node, indent);
}
private void adjustDescendantsIndent(Node node, int baseIndent) { private void adjustDescendantsIndent(Node node, int baseIndent) {
for (Node child : node.children) { for (Node child : node.children) {
child.indent = baseIndent + 1; child.indent = baseIndent + 1;
@ -212,7 +215,7 @@ public abstract class NewOrderedListUpdater<LIST> {
return; return;
moveThis.parent = newParent; moveThis.parent = newParent;
moveThis.indent = moveThis.parent.indent + 1; setNodeIndent(moveThis, newParent.indent + 1);
oldSiblings.remove(moveThis); oldSiblings.remove(moveThis);
if (newSiblings == oldSiblings && beforeIndex > nodeIndex) { if (newSiblings == oldSiblings && beforeIndex > nodeIndex) {
@ -240,9 +243,8 @@ public abstract class NewOrderedListUpdater<LIST> {
siblings.remove(index); siblings.remove(index);
for (Node child : task.children) { for (Node child : task.children) {
child.parent = parent; child.parent = parent;
child.indent = parent.indent + 1;
siblings.add(index, child); siblings.add(index, child);
adjustDescendantsIndent(child, child.indent); setNodeIndent(child, parent.indent + 1);
index++; index++;
} }
idToNode.remove(taskId); idToNode.remove(taskId);

Loading…
Cancel
Save