mirror of
https://github.com/makew0rld/amfora.git
synced 2025-01-03 14:56:27 -05:00
🚧 Fix bottomBar code
Make sure it always resets to a selected link if one was selected before
This commit is contained in:
parent
be09ffcf91
commit
4b8982723f
3
NOTES.md
3
NOTES.md
@ -2,8 +2,9 @@
|
||||
|
||||
- URL for each tab should not be stored as a string - in the current code there's lots of reparsing the URL
|
||||
|
||||
## Bugs
|
||||
## Issues
|
||||
- Can't go back or do other things while page is loading - need a way to stop `handleURL`
|
||||
- Change renderer to start style tags on each new line of wrapped link, to prevent left margin from being highlighted
|
||||
|
||||
## Upstream Bugs
|
||||
- Wrapping messes up on brackets
|
||||
|
@ -98,10 +98,17 @@ func Init() {
|
||||
}
|
||||
bottomBar.SetBackgroundColor(tcell.ColorWhite)
|
||||
bottomBar.SetDoneFunc(func(key tcell.Key) {
|
||||
defer bottomBar.SetLabel("")
|
||||
|
||||
tab := curTab
|
||||
|
||||
// Reset func to set the bottomBar back to what it was before
|
||||
// Use for errors.
|
||||
reset := func() {
|
||||
bottomBar.SetLabel("")
|
||||
tabs[tab].applySelected()
|
||||
tabs[tab].applyBottomBar()
|
||||
App.SetFocus(tabs[tab].view)
|
||||
}
|
||||
|
||||
switch key {
|
||||
case tcell.KeyEnter:
|
||||
// Figure out whether it's a URL, link number, or search
|
||||
@ -111,9 +118,7 @@ func Init() {
|
||||
|
||||
if strings.TrimSpace(query) == "" {
|
||||
// Ignore
|
||||
bottomBar.SetText(tabs[tab].page.Url)
|
||||
tabs[tab].saveBottomBar() // Store new bottomBar text
|
||||
App.SetFocus(tabs[tab].view)
|
||||
reset()
|
||||
return
|
||||
}
|
||||
if query == ".." && tabs[tab].hasContent() {
|
||||
@ -125,9 +130,7 @@ func Init() {
|
||||
}
|
||||
if parsed.Path == "/" {
|
||||
// Can't go up further
|
||||
bottomBar.SetText(tabs[tab].page.Url)
|
||||
tabs[tab].saveBottomBar()
|
||||
App.SetFocus(tabs[tab].view)
|
||||
reset()
|
||||
return
|
||||
}
|
||||
|
||||
@ -147,6 +150,7 @@ func Init() {
|
||||
// They're trying to open a link number in a new tab
|
||||
i, err = strconv.Atoi(query[4:])
|
||||
if err != nil {
|
||||
reset()
|
||||
return
|
||||
}
|
||||
if i <= len(tabs[tab].page.Links) && i > 0 {
|
||||
@ -158,6 +162,7 @@ func Init() {
|
||||
nextParsed, err := url.Parse(tabs[oldTab].page.Links[i-1])
|
||||
if err != nil {
|
||||
Error("URL Error", "link URL could not be parsed")
|
||||
reset()
|
||||
return
|
||||
}
|
||||
URL(prevParsed.ResolveReference(nextParsed).String())
|
||||
@ -184,15 +189,13 @@ func Init() {
|
||||
return
|
||||
}
|
||||
// Invalid link number, don't do anything
|
||||
bottomBar.SetText(tabs[tab].page.Url)
|
||||
tabs[tab].saveBottomBar()
|
||||
App.SetFocus(tabs[tab].view)
|
||||
reset()
|
||||
return
|
||||
|
||||
case tcell.KeyEscape:
|
||||
// Set back to what it was
|
||||
bottomBar.SetText(tabs[tab].page.Url)
|
||||
tabs[tab].saveBottomBar()
|
||||
App.SetFocus(tabs[tab].view)
|
||||
reset()
|
||||
return
|
||||
}
|
||||
// Other potential keys are Tab and Backtab, they are ignored
|
||||
})
|
||||
|
@ -212,6 +212,7 @@ func handleURL(t *tab, u string) (string, bool) {
|
||||
t.barLabel = oldLable
|
||||
t.barText = oldText
|
||||
}
|
||||
t.mode = tabModeDone
|
||||
return s, b
|
||||
}
|
||||
|
||||
@ -271,9 +272,6 @@ func handleURL(t *tab, u string) (string, bool) {
|
||||
bottomBar.SetText("Loading...")
|
||||
t.barText = "Loading..." // Save it too, in case the tab switches during loading
|
||||
t.mode = tabModeLoading
|
||||
defer func(tt *tab) {
|
||||
tt.mode = tabModeDone
|
||||
}(t)
|
||||
App.Draw()
|
||||
|
||||
res, err := client.Fetch(u)
|
||||
|
Loading…
Reference in New Issue
Block a user