Skip to content

Commit

Permalink
do not add to history in Content.handleWebPopState; only do saveWebUR…
Browse files Browse the repository at this point in the history
…L when adding to history; makes #1279 better, although still one more navigation issue
  • Loading branch information
kkoreilly committed Nov 20, 2024
1 parent 339a97c commit c81c4c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,27 @@ func (ct *Content) SetContent(content fs.FS) *Content {
// Open opens the page with the given URL and updates the display.
// If no pages correspond to the URL, it is opened in the default browser.
func (ct *Content) Open(url string) *Content {
ct.openPage(url, true)
return ct
}

// openPage opens the page with the given URL and updates the display.
// It optionally adds the page to the history.
func (ct *Content) openPage(url string, history bool) {
pg, ok := ct.pagesByURL[url]
if !ok {
core.TheApp.OpenURL(url)
return ct
return
}
ct.openPage(pg, true)
return ct
}

// openPage opens the given page. It optionally adds the page to the history.
func (ct *Content) openPage(pg *Page, history bool) {
if ct.currentPage == pg {
return
}
ct.currentPage = pg
if history {
ct.historyIndex = len(ct.history)
ct.history = append(ct.history, pg)
ct.saveWebURL()
}
ct.saveWebURL()
ct.Scene.Update() // need to also update toolbar
}

Expand Down Expand Up @@ -274,7 +275,7 @@ func (ct *Content) MakeToolbar(p *tree.Plan) {
})
w.OnClick(func(e events.Event) {
ct.historyIndex--
ct.openPage(ct.history[ct.historyIndex], false)
ct.openPage(ct.history[ct.historyIndex].URL, false) // do not add to history while navigating history
})
})
tree.Add(p, func(w *core.Button) {
Expand All @@ -285,7 +286,7 @@ func (ct *Content) MakeToolbar(p *tree.Plan) {
})
w.OnClick(func(e events.Event) {
ct.historyIndex++
ct.openPage(ct.history[ct.historyIndex], false)
ct.openPage(ct.history[ct.historyIndex].URL, false) // do not add to history while navigating history
})
})
tree.Add(p, func(w *core.Button) {
Expand Down
2 changes: 1 addition & 1 deletion content/url_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (ct *Content) saveWebURL() {
// handleWebPopState adds a JS event listener to handle user navigation in the browser.
func (ct *Content) handleWebPopState() {
js.Global().Get("window").Call("addEventListener", "popstate", js.FuncOf(func(this js.Value, args []js.Value) any {
ct.Open(ct.getWebURL())
ct.openPage(ct.getWebURL(), false) // do not add to history while navigating history
return nil
}))
}
Expand Down

0 comments on commit c81c4c4

Please sign in to comment.