shithub: mycel

Download patch

ref: 8f4713facefc9e53ac6ef882f38cc1173ac1a610
parent: 39fbbc82730c62ce4d127454761c2d5bd7218cc4
author: Philip Silva <philip.silva@protonmail.com>
date: Sat Mar 27 09:02:39 EDT 2021

Prevent dups in history

--- a/browser/browser.go
+++ b/browser/browser.go
@@ -1243,6 +1243,9 @@
 }
 
 func (h *History) Push(u *url.URL) {
+	if len(h.urls) > 0 && h.urls[len(h.urls)-1].String() == u.String() {
+		return
+	}
 	h.urls = append(h.urls, u)
 }
 
--- a/browser/browser_test.go
+++ b/browser/browser_test.go
@@ -382,3 +382,25 @@
 	// Trigger key press to trigger call to changed
 	el.Key(nil, nil, 'a', draw.Mouse{}, image.Point{})
 }
+
+func TestHistoryNoDup(t *testing.T) {
+	h := History{}
+	uris := []string{
+		"https://example.com",
+		"https://example.com/a",
+		"https://example.com/a",
+		"https://example.com/b",
+		"https://example.com/b",
+	}
+	for _, uri := range uris {
+		u, err := url.Parse(uri)
+		if err != nil {
+			t.Error()
+		}
+		h.Push(u)
+	}
+	if len(h.urls) != 3 {
+		t.Error()
+	}
+}
+