From 27a041a746896b590ee4029a763387b5d5a2733e Mon Sep 17 00:00:00 2001 From: makeworld Date: Mon, 28 Dec 2020 14:05:00 -0500 Subject: [PATCH] Fix tab number and favicons when moving through history --- display/handlers.go | 5 ++--- display/private.go | 18 +++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/display/handlers.go b/display/handlers.go index a3239cd..5df327f 100644 --- a/display/handlers.go +++ b/display/handlers.go @@ -91,11 +91,10 @@ func handleOther(u string) { } // handleFavicon handles getting and displaying a favicon. -// `old` is the previous favicon for the tab. -func handleFavicon(t *tab, host, old string) { +func handleFavicon(t *tab, host string) { defer func() { // Update display if needed - if t.page.Favicon != old && isValidTab(t) { + if t.page.Favicon != "" && isValidTab(t) { browser.SetTabLabel(strconv.Itoa(tabNumber(t)), t.page.Favicon) App.Draw() } diff --git a/display/private.go b/display/private.go index b721e76..2740113 100644 --- a/display/private.go +++ b/display/private.go @@ -2,6 +2,7 @@ package display import ( "net/url" + "strconv" "strings" "github.com/makeworld-the-better-one/amfora/renderer" @@ -103,20 +104,23 @@ func setPage(t *tab, p *structs.Page) { // Make sure the page content is fitted to the terminal every time it's displayed reformatPage(p) - oldFav := t.page.Favicon - t.page = p - go func() { - parsed, _ := url.Parse(p.URL) - handleFavicon(t, parsed.Host, oldFav) - }() - // Change page on screen t.view.SetText(p.Content) t.view.Highlight("") // Turn off highlights, other funcs may restore if necessary t.view.ScrollToBeginning() + // Set tab number in case a favicon from before overwrote it + tabNum := tabNumber(t) + browser.SetTabLabel(strconv.Itoa(tabNum), strconv.Itoa(tabNum+1)) + App.Draw() + + go func() { + parsed, _ := url.Parse(p.URL) + handleFavicon(t, parsed.Host) + }() + // Setup display App.SetFocus(t.view)