Skip to content

fix: correctly reassign siblings in linked list #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2022
Merged
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
20 changes: 14 additions & 6 deletions packages/angular/src/lib/view-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export class ViewUtil {
NativeScriptDebug.viewUtilLog(`ViewUtil.removeFromList parent: ${parent} child: ${child}`);
}

// only child. null everything
if (parent.firstChild === child && parent.lastChild === child) {
parent.firstChild = null;
parent.lastChild = null;
Expand All @@ -232,22 +233,29 @@ export class ViewUtil {
return;
}

const previous = child.previousSibling;
const next = child.nextSibling;
// is first child, make the next sibling the first child (can be null)
if (parent.firstChild === child) {
parent.firstChild = child.nextSibling;
parent.firstChild = next;
}

const previous = child.previousSibling;
// is last child, make the previous sibling the last child (can be null)
if (parent.lastChild === child) {
parent.lastChild = previous;
}

// we have a previous sibling, make it point to the next sibling
if (previous) {
previous.nextSibling = child.nextSibling;
if (child.nextSibling) {
child.nextSibling.previousSibling = previous;
}
previous.nextSibling = next;
}

// we have a next sibling, make it point to the previous
if (next) {
next.previousSibling = previous;
}

// finally, null the siblings
child.nextSibling = null;
child.previousSibling = null;
}
Expand Down