Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

fix(node cursor): Do not eat nodes #50

Merged
merged 1 commit into from
Jul 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/node_cursor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ class NodeCursor {
var nodes = nodeList();

for (var i = 0, ii = nodes.length; i < ii; i++) {
nodes[i].remove();
// NOTE(deboer): If elements is a list of child nodes on a node, then
// calling Node.remove() may also remove it from the list. Thus, we
// call elements.removeAt first so only one node is removed.
elements.removeAt(index);
nodes[i].remove();
}

return new NodeCursor(nodes);
Expand Down
10 changes: 10 additions & 0 deletions test/node_cursor_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ main() {

expect(STRINGIFY(childCursor.elements[0]), equals('<span>text</span>'));
});

it('should preserve the top-level elements', () {
var dom = $('<span>text</span>MoreText<div>other</div>');
var parentCursor = new NodeCursor(dom);

var childCursor = parentCursor.replaceWithAnchor('child');
expect(STRINGIFY(dom), equals('[<!--ANCHOR: child-->, MoreText, <div>other</div>]'));

expect(STRINGIFY(childCursor.elements[0]), equals('<span>text</span>'));
});
});
}

Expand Down