From 61e2c51e40682f0f3a2a60fb4c2fb51a3e8ad280 Mon Sep 17 00:00:00 2001 From: makeworld Date: Sun, 21 Jun 2020 17:15:21 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20New=20tab=20is=20now=20shifted?= =?UTF-8?q?=20too=20-=20with=20prev.=20commit,=20this=20fixes=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- display/display.go | 9 ++++++++- display/private.go | 14 +++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/display/display.go b/display/display.go index edba031..c612b13 100644 --- a/display/display.go +++ b/display/display.go @@ -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() }). diff --git a/display/private.go b/display/private.go index a1649f4..bb6f2e0 100644 --- a/display/private.go +++ b/display/private.go @@ -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 }