|
700 | 700 | t1_child_nodes = t1.childNodes ? t1.childNodes : [], |
701 | 701 | t2_child_nodes = t2.childNodes ? t2.childNodes : [], |
702 | 702 | childNodesLengthDifference, diffs = [], |
703 | | - i, last, e1, e2; |
| 703 | + index = 0, last, e1, e2, i; |
704 | 704 |
|
705 | 705 | if (subtrees.length > 1) { |
706 | 706 | /* Two or more groups have been identified among the childnodes of t1 |
|
733 | 733 | if (e1.nodeName === '#text') { |
734 | 734 | diffs.push(new Diff({ |
735 | 735 | action: 'removeTextElement', |
736 | | - route: route.concat(i), |
| 736 | + route: route.concat(index), |
737 | 737 | value: e1.data |
738 | 738 | })); |
739 | | - return diffs; |
| 739 | + index -= 1; |
| 740 | + } else { |
| 741 | + diffs.push(new Diff({ |
| 742 | + action: 'removeElement', |
| 743 | + route: route.concat(index), |
| 744 | + element: cloneObj(e1) |
| 745 | + })); |
| 746 | + index -= 1; |
740 | 747 | } |
741 | | - diffs.push(new Diff({ |
742 | | - action: 'removeElement', |
743 | | - route: route.concat(i), |
744 | | - element: cloneObj(e1) |
745 | | - })); |
746 | | - return diffs; |
747 | | - } |
748 | | - if (e2 && !e1) { |
| 748 | + |
| 749 | + } else if (e2 && !e1) { |
749 | 750 | if (e2.nodeName === '#text') { |
750 | 751 | diffs.push(new Diff({ |
751 | 752 | action: 'addTextElement', |
752 | | - route: route.concat(i), |
| 753 | + route: route.concat(index), |
753 | 754 | value: e2.data |
754 | 755 | })); |
755 | | - return diffs; |
| 756 | + } else { |
| 757 | + diffs.push(new Diff({ |
| 758 | + action: 'addElement', |
| 759 | + route: route.concat(index), |
| 760 | + element: cloneObj(e2) |
| 761 | + })); |
756 | 762 | } |
757 | | - diffs.push(new Diff({ |
758 | | - action: 'addElement', |
759 | | - route: route.concat(i), |
760 | | - element: cloneObj(e2) |
761 | | - })); |
762 | | - return diffs; |
763 | 763 | } |
764 | 764 | } |
765 | 765 | /* We are now guaranteed that childNodes e1 and e2 exist, |
766 | 766 | * and that they can be diffed. |
767 | 767 | */ |
768 | | - diffs = diffs.concat(this.findNextDiff(e1, e2, route.concat(i))); |
| 768 | + /* Diffs in child nodes should not affect the parent node, |
| 769 | + * so we let these diffs be submitted together with other |
| 770 | + * diffs. |
| 771 | + */ |
769 | 772 |
|
770 | | - /* Diffs in child nodes should not affect the parent node, |
771 | | - * so we let these diffs be submitted together with other |
772 | | - * diffs. |
773 | | - */ |
| 773 | + if (e1 && e2) { |
| 774 | + diffs = diffs.concat(this.findNextDiff(e1, e2, route.concat(index))); |
| 775 | + } |
| 776 | + |
| 777 | + index += 1; |
774 | 778 |
|
775 | 779 | } |
776 | 780 |
|
|
0 commit comments