diff --git a/display/display.go b/display/display.go index 402f9c7..db41fe9 100644 --- a/display/display.go +++ b/display/display.go @@ -104,8 +104,7 @@ func Init() { // Use for errors. reset := func() { bottomBar.SetLabel("") - tabs[tab].applySelected() - tabs[tab].applyBottomBar() + tabs[tab].applyAll() App.SetFocus(tabs[tab].view) } @@ -454,8 +453,7 @@ func CloseTab() { tabRow.Highlight(strconv.Itoa(curTab)).ScrollToHighlight() // Restore previous tab's state - tabs[curTab].applySelected() - tabs[curTab].applyBottomBar() + tabs[curTab].applyAll() App.SetFocus(tabs[curTab].view) @@ -486,8 +484,7 @@ func SwitchTab(tab int) { reformatPageAndSetView(tabs[curTab], tabs[curTab].page) tabPages.SwitchToPage(strconv.Itoa(curTab)) tabRow.Highlight(strconv.Itoa(curTab)).ScrollToHighlight() - tabs[curTab].applySelected() - tabs[curTab].applyBottomBar() + tabs[curTab].applyAll() App.SetFocus(tabs[curTab].view) @@ -500,7 +497,7 @@ func Reload() { return } - cache.Remove(tabs[curTab].page.Url) + go cache.Remove(tabs[curTab].page.Url) go func(t *tab) { handleURL(t, t.page.Url) // goURL is not used bc history shouldn't be added to if t == tabs[curTab] { diff --git a/display/history.go b/display/history.go index 3a8cb9f..df60641 100644 --- a/display/history.go +++ b/display/history.go @@ -1,20 +1,18 @@ package display +// applyHist is a history.go internal function, to load a URL in the history. +func applyHist(t *tab) { + handleURL(t, t.history.urls[t.history.pos]) // Load that position in history + t.applyAll() +} + func histForward(t *tab) { if t.history.pos >= len(t.history.urls)-1 { // Already on the most recent URL in the history return } t.history.pos++ - go func(tt *tab) { - handleURL(tt, tt.history.urls[tt.history.pos]) // Load that position in history - tt.applyScroll() - tt.applySelected() - if tt == tabs[curTab] { - // Display the bottomBar state that handleURL set - tt.applyBottomBar() - } - }(t) + go applyHist(t) } func histBack(t *tab) { @@ -23,13 +21,5 @@ func histBack(t *tab) { return } t.history.pos-- - go func(tt *tab) { - handleURL(tt, tt.history.urls[tt.history.pos]) // Load that position in history - tt.applyScroll() - tt.applySelected() - if tt == tabs[curTab] { - // Display the bottomBar state that handleURL set - tt.applyBottomBar() - } - }(t) + go applyHist(t) } diff --git a/display/private.go b/display/private.go index a4c89eb..d67831f 100644 --- a/display/private.go +++ b/display/private.go @@ -20,8 +20,9 @@ import ( // isValidTab indicates whether the passed tab is still being used, even if it's not currently displayed. func isValidTab(t *tab) bool { - for i := range tabs { - if tabs[i] == t { + tempTabs := tabs + for i := range tempTabs { + if tempTabs[i] == t { return true } } diff --git a/display/tab.go b/display/tab.go index 7e6c0d4..78d34f6 100644 --- a/display/tab.go +++ b/display/tab.go @@ -209,7 +209,7 @@ func (t *tab) applySelected() { t.view.Highlight("") return } else if t.page.Mode == structs.ModeLinkSelect { - t.view.Highlight(t.page.SelectedID).ScrollToHighlight() + t.view.Highlight(t.page.SelectedID) if t.mode == tabModeDone { // Page is not loading so bottomBar can change @@ -218,3 +218,13 @@ func (t *tab) applySelected() { } } } + +// applyAll uses applyScroll and applySelected to put a tab's TextView back the way it was. +// It also uses applyBottomBar if this is the current tab. +func (t *tab) applyAll() { + t.applySelected() + t.applyScroll() + if t == tabs[curTab] { + t.applyBottomBar() + } +}