1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-11-03 02:37:23 -05:00

🐛 New tab is now shifted too - with prev. commit, this fixes #1

This commit is contained in:
makeworld 2020-06-21 17:15:21 -04:00
parent 850d6f0454
commit 61e2c51e40
2 changed files with 17 additions and 6 deletions

View File

@ -83,6 +83,13 @@ var App = cview.NewApplication().
// Store width and height for calculations
termW = width
termH = height
// Shift new tabs created before app startup, when termW == 0
// XXX: This is hacky but works. The biggest issue is that there will sometimes be a tiny flash
// of the old not shifted tab on startup.
if tabMap[curTab] == &newTabPage {
tabViews[curTab].SetText(addLeftMargin(renderedNewTabContent))
}
})
var renderedNewTabContent string
@ -289,7 +296,7 @@ func NewTab() {
SetRegions(true).
SetScrollable(true).
SetWrap(false).
SetText(renderedNewTabContent).
SetText(addLeftMargin(renderedNewTabContent)).
SetChangedFunc(func() {
App.Draw()
}).

View File

@ -100,17 +100,21 @@ func followLink(prev, next string) {
}()
}
func addLeftMargin(text string) string {
var shifted string
for _, line := range strings.Split(text, "\n") {
shifted += strings.Repeat(" ", leftMargin()) + line + "\n"
}
return shifted
}
// setPage displays a Page on the current tab.
func setPage(p *structs.Page) {
saveScroll() // Save the scroll of the previous page
if !p.Displayable {
// Add margin to page based on terminal width
var shifted string
for _, line := range strings.Split(p.Content, "\n") {
shifted += strings.Repeat(" ", leftMargin()) + line + "\n"
}
p.Content = shifted
p.Content = addLeftMargin(p.Content)
p.Displayable = true
}