diff --git a/NOTES.md b/NOTES.md index efd38c5..4e714b6 100644 --- a/NOTES.md +++ b/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 diff --git a/display/display.go b/display/display.go index 43ed6c5..402f9c7 100644 --- a/display/display.go +++ b/display/display.go @@ -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 }) diff --git a/display/private.go b/display/private.go index b4b1447..a4c89eb 100644 --- a/display/private.go +++ b/display/private.go @@ -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)