mirror of
https://github.com/makew0rld/amfora.git
synced 2024-09-23 22:45:54 -04: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
|
- 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`
|
- 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
|
## Upstream Bugs
|
||||||
- Wrapping messes up on brackets
|
- Wrapping messes up on brackets
|
||||||
|
@ -98,10 +98,17 @@ func Init() {
|
|||||||
}
|
}
|
||||||
bottomBar.SetBackgroundColor(tcell.ColorWhite)
|
bottomBar.SetBackgroundColor(tcell.ColorWhite)
|
||||||
bottomBar.SetDoneFunc(func(key tcell.Key) {
|
bottomBar.SetDoneFunc(func(key tcell.Key) {
|
||||||
defer bottomBar.SetLabel("")
|
|
||||||
|
|
||||||
tab := curTab
|
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 {
|
switch key {
|
||||||
case tcell.KeyEnter:
|
case tcell.KeyEnter:
|
||||||
// Figure out whether it's a URL, link number, or search
|
// Figure out whether it's a URL, link number, or search
|
||||||
@ -111,9 +118,7 @@ func Init() {
|
|||||||
|
|
||||||
if strings.TrimSpace(query) == "" {
|
if strings.TrimSpace(query) == "" {
|
||||||
// Ignore
|
// Ignore
|
||||||
bottomBar.SetText(tabs[tab].page.Url)
|
reset()
|
||||||
tabs[tab].saveBottomBar() // Store new bottomBar text
|
|
||||||
App.SetFocus(tabs[tab].view)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if query == ".." && tabs[tab].hasContent() {
|
if query == ".." && tabs[tab].hasContent() {
|
||||||
@ -125,9 +130,7 @@ func Init() {
|
|||||||
}
|
}
|
||||||
if parsed.Path == "/" {
|
if parsed.Path == "/" {
|
||||||
// Can't go up further
|
// Can't go up further
|
||||||
bottomBar.SetText(tabs[tab].page.Url)
|
reset()
|
||||||
tabs[tab].saveBottomBar()
|
|
||||||
App.SetFocus(tabs[tab].view)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +150,7 @@ func Init() {
|
|||||||
// They're trying to open a link number in a new tab
|
// They're trying to open a link number in a new tab
|
||||||
i, err = strconv.Atoi(query[4:])
|
i, err = strconv.Atoi(query[4:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
reset()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if i <= len(tabs[tab].page.Links) && i > 0 {
|
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])
|
nextParsed, err := url.Parse(tabs[oldTab].page.Links[i-1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error("URL Error", "link URL could not be parsed")
|
Error("URL Error", "link URL could not be parsed")
|
||||||
|
reset()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
URL(prevParsed.ResolveReference(nextParsed).String())
|
URL(prevParsed.ResolveReference(nextParsed).String())
|
||||||
@ -184,15 +189,13 @@ func Init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Invalid link number, don't do anything
|
// Invalid link number, don't do anything
|
||||||
bottomBar.SetText(tabs[tab].page.Url)
|
reset()
|
||||||
tabs[tab].saveBottomBar()
|
return
|
||||||
App.SetFocus(tabs[tab].view)
|
|
||||||
|
|
||||||
case tcell.KeyEscape:
|
case tcell.KeyEscape:
|
||||||
// Set back to what it was
|
// Set back to what it was
|
||||||
bottomBar.SetText(tabs[tab].page.Url)
|
reset()
|
||||||
tabs[tab].saveBottomBar()
|
return
|
||||||
App.SetFocus(tabs[tab].view)
|
|
||||||
}
|
}
|
||||||
// Other potential keys are Tab and Backtab, they are ignored
|
// 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.barLabel = oldLable
|
||||||
t.barText = oldText
|
t.barText = oldText
|
||||||
}
|
}
|
||||||
|
t.mode = tabModeDone
|
||||||
return s, b
|
return s, b
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,9 +272,6 @@ func handleURL(t *tab, u string) (string, bool) {
|
|||||||
bottomBar.SetText("Loading...")
|
bottomBar.SetText("Loading...")
|
||||||
t.barText = "Loading..." // Save it too, in case the tab switches during loading
|
t.barText = "Loading..." // Save it too, in case the tab switches during loading
|
||||||
t.mode = tabModeLoading
|
t.mode = tabModeLoading
|
||||||
defer func(tt *tab) {
|
|
||||||
tt.mode = tabModeDone
|
|
||||||
}(t)
|
|
||||||
App.Draw()
|
App.Draw()
|
||||||
|
|
||||||
res, err := client.Fetch(u)
|
res, err := client.Fetch(u)
|
||||||
|
Loading…
Reference in New Issue
Block a user