1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-12-04 14:46:29 -05:00

Selected link and scroll position stays for non-cached pages

Fixes #122
This commit is contained in:
makeworld 2021-12-26 16:22:29 -05:00
parent 004851f651
commit 03c4d3e286
5 changed files with 65 additions and 9 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Syntax highlighting for preformatted text blocks with alt text (#252, #263, [wiki page](https://github.com/makeworld-the-better-one/amfora/wiki/Source-Code-Highlighting))
- [Client certificates](https://github.com/makeworld-the-better-one/amfora/wiki/Client-Certificates) can be restricted to certain paths of a host (#115)
- `header` config option in `[subscriptions]` to allow disabling the header text on the subscriptions page (#191)
- Selected link and scroll position stays for non-cached pages (#122)
### Changed
- Center text automatically, removing `left_margin` from the config (#233)

View File

@ -3,6 +3,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], 0) // Load that position in history
// Set page's scroll and link info from history cache, in case it didn't have it in the page already
// Like for non-cached pages like about: pages
// This fixes #122
pg := t.history.pageCache[t.history.pos]
p := t.page
p.Row = pg.row
p.Column = pg.column
p.Selected = pg.selected
p.SelectedID = pg.selectedID
p.Mode = pg.mode
t.applyAll()
}
@ -11,6 +23,10 @@ func histForward(t *tab) {
// Already on the most recent URL in the history
return
}
// Update page cache in history for #122
t.historyCachePage()
t.history.pos++
go applyHist(t)
}
@ -20,6 +36,10 @@ func histBack(t *tab) {
// First tab in history
return
}
// Update page cache in history for #122
t.historyCachePage()
t.history.pos--
go applyHist(t)
}

View File

@ -137,6 +137,9 @@ func setPage(t *tab, p *structs.Page) {
//
// It should be called in a goroutine.
func goURL(t *tab, u string) {
// Update page cache in history for #122
t.historyCachePage()
final, displayed := handleURL(t, u, 0)
if displayed {
t.addToHistory(final)

View File

@ -20,9 +20,20 @@ const (
tabModeLoading
)
// tabHistoryPageCache is fields from the Page struct, cached here to solve #122
// See structs/structs.go for an explanation of the fields.
type tabHistoryPageCache struct {
row int
column int
selected string
selectedID string
mode structs.PageMode
}
type tabHistory struct {
urls []string
pos int // Position: where in the list of URLs we are
urls []string
pos int // Position: where in the list of URLs we are
pageCache []*tabHistoryPageCache
}
// tab hold the information needed for each browser tab.
@ -290,6 +301,21 @@ func makeNewTab() *tab {
return &t
}
// historyCachePage caches certain info about the current page in the tab's history,
// see #122 for details.
func (t *tab) historyCachePage() {
if t.page == nil || t.page.URL == "" || t.history.pageCache == nil || len(t.history.pageCache) == 0 {
return
}
t.history.pageCache[t.history.pos] = &tabHistoryPageCache{
row: t.page.Row,
column: t.page.Column,
selected: t.page.Selected,
selectedID: t.page.SelectedID,
mode: t.page.Mode,
}
}
// addToHistory adds the given URL to history.
// It assumes the URL is currently being loaded and displayed on the page.
func (t *tab) addToHistory(u string) {
@ -297,9 +323,15 @@ func (t *tab) addToHistory(u string) {
// We're somewhere in the middle of the history instead, with URLs ahead and behind.
// The URLs ahead need to be removed so this new URL is the most recent item in the history
t.history.urls = t.history.urls[:t.history.pos+1]
// Same for page cache
t.history.pageCache = t.history.pageCache[:t.history.pos+1]
}
t.history.urls = append(t.history.urls, u)
t.history.pos++
// Cache page info for #122
t.history.pageCache = append(t.history.pageCache, &tabHistoryPageCache{}) // Add new spot
t.historyCachePage() // Fill it with data
}
// pageUp scrolls up 75% of the height of the terminal, like Bombadillo.

View File

@ -9,11 +9,11 @@ import (
"os"
)
var logger *log.Logger
var Logger *log.Logger
func GetLogger() (*log.Logger, error) {
if logger != nil {
return logger, nil
if Logger != nil {
return Logger, nil
}
var writer io.Writer
@ -30,15 +30,15 @@ func GetLogger() (*log.Logger, error) {
writer = ioutil.Discard
}
logger = log.New(writer, "", log.LstdFlags)
Logger = log.New(writer, "", log.LstdFlags)
if !debugModeEnabled {
// Clear all flags to skip log output formatting step to increase
// performance somewhat if we're not logging anything
logger.SetFlags(0)
Logger.SetFlags(0)
}
logger.Println("Started logger")
Logger.Println("Started logger")
return logger, nil
return Logger, nil
}