1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-15 19:15:24 +00:00

🚧 Scroll is applied correctly when navigating around

This commit is contained in:
makeworld 2020-07-07 16:15:45 -04:00
parent 4b8982723f
commit 72f36afc9e
4 changed files with 26 additions and 28 deletions

View File

@ -104,8 +104,7 @@ func Init() {
// Use for errors. // Use for errors.
reset := func() { reset := func() {
bottomBar.SetLabel("") bottomBar.SetLabel("")
tabs[tab].applySelected() tabs[tab].applyAll()
tabs[tab].applyBottomBar()
App.SetFocus(tabs[tab].view) App.SetFocus(tabs[tab].view)
} }
@ -454,8 +453,7 @@ func CloseTab() {
tabRow.Highlight(strconv.Itoa(curTab)).ScrollToHighlight() tabRow.Highlight(strconv.Itoa(curTab)).ScrollToHighlight()
// Restore previous tab's state // Restore previous tab's state
tabs[curTab].applySelected() tabs[curTab].applyAll()
tabs[curTab].applyBottomBar()
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
@ -486,8 +484,7 @@ func SwitchTab(tab int) {
reformatPageAndSetView(tabs[curTab], tabs[curTab].page) reformatPageAndSetView(tabs[curTab], tabs[curTab].page)
tabPages.SwitchToPage(strconv.Itoa(curTab)) tabPages.SwitchToPage(strconv.Itoa(curTab))
tabRow.Highlight(strconv.Itoa(curTab)).ScrollToHighlight() tabRow.Highlight(strconv.Itoa(curTab)).ScrollToHighlight()
tabs[curTab].applySelected() tabs[curTab].applyAll()
tabs[curTab].applyBottomBar()
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
@ -500,7 +497,7 @@ func Reload() {
return return
} }
cache.Remove(tabs[curTab].page.Url) go cache.Remove(tabs[curTab].page.Url)
go func(t *tab) { go func(t *tab) {
handleURL(t, t.page.Url) // goURL is not used bc history shouldn't be added to handleURL(t, t.page.Url) // goURL is not used bc history shouldn't be added to
if t == tabs[curTab] { if t == tabs[curTab] {

View File

@ -1,20 +1,18 @@
package display 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) { func histForward(t *tab) {
if t.history.pos >= len(t.history.urls)-1 { if t.history.pos >= len(t.history.urls)-1 {
// Already on the most recent URL in the history // Already on the most recent URL in the history
return return
} }
t.history.pos++ t.history.pos++
go func(tt *tab) { go applyHist(t)
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)
} }
func histBack(t *tab) { func histBack(t *tab) {
@ -23,13 +21,5 @@ func histBack(t *tab) {
return return
} }
t.history.pos-- t.history.pos--
go func(tt *tab) { go applyHist(t)
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)
} }

View File

@ -20,8 +20,9 @@ import (
// isValidTab indicates whether the passed tab is still being used, even if it's not currently displayed. // isValidTab indicates whether the passed tab is still being used, even if it's not currently displayed.
func isValidTab(t *tab) bool { func isValidTab(t *tab) bool {
for i := range tabs { tempTabs := tabs
if tabs[i] == t { for i := range tempTabs {
if tempTabs[i] == t {
return true return true
} }
} }

View File

@ -209,7 +209,7 @@ func (t *tab) applySelected() {
t.view.Highlight("") t.view.Highlight("")
return return
} else if t.page.Mode == structs.ModeLinkSelect { } else if t.page.Mode == structs.ModeLinkSelect {
t.view.Highlight(t.page.SelectedID).ScrollToHighlight() t.view.Highlight(t.page.SelectedID)
if t.mode == tabModeDone { if t.mode == tabModeDone {
// Page is not loading so bottomBar can change // 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()
}
}