Skip to content
This repository was archived by the owner on May 25, 2026. It is now read-only.

Commit e37466c

Browse files
committed
Bug fixses
1 parent 474da7e commit e37466c

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

FUTURE-CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
## v0.0.0-beta.3 <- current
22

33
## v0.0.0
4-
Delete deletes the node without connecting sibling nodes.
5-
* Delete
6-
74
QuerySelector takes attribute name and regexp for the value and returns the first node that matches the regexp.
85
* QuerySelector
96

node-tree.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ func (node *Node) RemoveNode() {
229229

230230
node.previousNode = nil
231231
node.nextNode = nil
232+
node.parentNode = nil
232233

233234
node.rwMutex.Unlock()
234235

@@ -239,9 +240,13 @@ func (node *Node) RemoveNode() {
239240
nextNode.SetPreviousNode(previousNode)
240241
}
241242

242-
if nextNode != nil{
243+
if nextNode != nil && previousNode == nil{
243244
nextNode.setParentNode(parentNode)
244245
}
246+
247+
if parentNode != nil{
248+
parentNode.childNode = nextNode
249+
}
245250
}
246251

247252
// IsTextNode returns a boolean value indicating node is a text node or not.

node-tree_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,27 @@ func TestAppendTextAndInnerText(t *testing.T){
8686
t.Fatal(body.GetInnerText(), " != ", h1.GetChildNode().GetText() + p.GetChildNode().GetText())
8787
}
8888

89+
}
90+
91+
func TestRemoveNode(t *testing.T){
92+
article := GoHtml.CreateNode("article")
93+
94+
h1 := GoHtml.CreateNode("h1")
95+
h1.AppendText("This is a heading.")
96+
article.AppendChild(h1)
97+
98+
article.AppendChild(GoHtml.CreateNode(GoHtml.Br))
99+
100+
p := GoHtml.CreateNode("p")
101+
p.AppendText("this is a paragraph.")
102+
article.AppendChild(p)
103+
104+
h1.RemoveNode()
105+
106+
if article.GetChildNode().GetTagName() != GoHtml.Br{
107+
t.Fatal("Unexpected tag. ", article.GetChildNode().GetTagName())
108+
return
109+
}else if p.GetParent() != article {
110+
t.Fatal("Unexpected parent.")
111+
}
89112
}

0 commit comments

Comments
 (0)