diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..e69de29 diff --git a/list-editor/store.js b/list-editor/store.js index 7fd3f83..dd9ac6e 100644 --- a/list-editor/store.js +++ b/list-editor/store.js @@ -349,22 +349,34 @@ function Store(inputData) { const stack = _.reduce(items, (stack, item) => { if (stack.length === 0) { + // console.log(`push ${item.text} on stack`) return [[item]] } - const stackIndented = top(stack)[0].indented + let stackIndented = top(stack)[0].indented const itemIndented = item.indented if (itemIndented > stackIndented) { - push(stack, [Object.assign({}, item)]) + push(stack, [Object.assign({}, item)]) // [ ... ] => [ ..., item ] + // console.log(`push ${item.text} on stack`) } else { + // console.log(`itemIndented = ${itemIndented}, stackIndented = ${stackIndented}`) while (stack.length > 1 && itemIndented < stackIndented) { let children = top(stack) - pop(stack) + pop(stack) // [ ..., A ] => [ ... ] + stackIndented = top(stack)[0].indented + // console.log(`pop stack`) let cur = top(stack) cur[cur.length - 1].children = children + // console.log(`set children for ${cur[cur.length-1].text}`) + } + if (itemIndented === stackIndented) { + top(stack).push(Object.assign({}, item)) + // console.log(`add child ${item.text}`) + } else { + push(stack, [Object.assign({}, item)]) + // console.log(`push ${item.text} on stack`) } - top(stack).push(Object.assign({}, item)) } return stack }, [])