shithub: mycel

Download patch

ref: e5a8744557758bf4592551225a60ceaf592a9c8c
parent: 0c7f8a96e75bae3529407d210ce73e269f7ff885
author: Philip Silva <philip.silva@protonmail.com>
date: Sat Apr 9 15:10:00 EDT 2022

Better click handling

- correct query refs
- cancel event once consumed

--- a/browser/browser.go
+++ b/browser/browser.go
@@ -809,7 +809,9 @@
 func (el *Element) click() (consumed bool) {
 	if ExperimentalJsInsecure {
 		q := el.n.QueryRef()
-		res, consumed, err := js.TriggerClick(q)
+		var res string
+		var err error
+		res, consumed, err = js.TriggerClick(q)
 		if err != nil {
 			log.Errorf("trigger click %v: %v", q, err)
 		} else if consumed {
--- a/nodes/nodes.go
+++ b/nodes/nodes.go
@@ -288,7 +288,7 @@
 		if c == n {
 			break
 		}
-		if c.Type() == html.ElementNode {
+		if c.Type() == html.ElementNode && c.Data() == n.Data() {
 			i++
 		}
 	}
--- a/nodes/nodes_test.go
+++ b/nodes/nodes_test.go
@@ -35,7 +35,7 @@
 	nt := NewNodeTree(doc, style.Map{}, make(map[*html.Node]style.Map), nil)
 	p := nt.Children[0].Children[1].Children[0]
 	a := p.Children[2]
-	if q := a.QueryRef(); q != "p:nth-child(1) > a:nth-child(3)" {
+	if q := a.QueryRef(); q != "p:nth-child(1) > a:nth-child(1)" {
 		t.Fatalf("%v", q)
 	}
 }