From 728e09564e7a84dd8ebc2e0c8841ee3e38c0c24b Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Wed, 22 Sep 2021 13:30:25 -0400 Subject: [PATCH] tab: Improve duplicate page removal --- tab.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/tab.go b/tab.go index 70c8b47..3eb739e 100644 --- a/tab.go +++ b/tab.go @@ -134,6 +134,17 @@ func (t *Tab) setText(text *Text) { } page.Text = text t.view.Invalidate() + + // Remove duplicate pages + if len(t.pages) < 2 { + return + } + i, j := len(t.pages)-1, len(t.pages)-2 + if t.pages[i].URL == t.pages[j].URL { + t.pages[j] = t.pages[i] + t.pages = t.pages[:i] + t.page-- + } } // Clone returns a new tab with the same URL and navigation history. @@ -417,7 +428,6 @@ func (t *Tab) do(ctx context.Context, req *gemini.Request, via []*gemini.Request return nil case gemini.StatusSuccess: - t.removeDuplicatePage() t.buf.Reset() resp.Body = &teeReader{resp.Body, &t.buf} return t.handle(req, resp) @@ -623,20 +633,6 @@ func (t *Tab) newPage() { t.pages = append(t.pages, Page{}) } -func (t *Tab) removeDuplicatePage() { - t.mu.Lock() - defer t.mu.Unlock() - if len(t.pages) < 2 { - return - } - i, j := len(t.pages)-1, len(t.pages)-2 - if t.pages[i].URL == t.pages[j].URL { - t.pages[j] = t.pages[i] - t.pages = t.pages[:i] - t.page-- - } -} - func (t *Tab) handle(req *gemini.Request, resp *gemini.Response) error { defer resp.Body.Close() -- 2.38.5