From cfd01d90d22c826ff5939233ddd3b229436c9402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Sun, 1 Jan 2023 21:22:16 -0500 Subject: [PATCH] Fixed view caching --- ui/views/posts/posts.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/views/posts/posts.go b/ui/views/posts/posts.go index 8365e33..4c0ec72 100644 --- a/ui/views/posts/posts.go +++ b/ui/views/posts/posts.go @@ -130,7 +130,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } else if m.focused == "post" { m.focused = "reply" - m.viewcache = m.View() + m.ctx.Logger.Debugln("caching view") + m.ctx.Logger.Debugf("buffer: %s", m.buffer) + m.viewcache = m.buildView(false) return m, m.textarea.Focus() } @@ -216,9 +218,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m Model) View() string { + return m.buildView(true) +} + +func (m Model) buildView(cached bool) string { var view strings.Builder = strings.Builder{} - if m.focused == "reply" && m.viewcache != "" { + if cached && m.focused == "reply" && m.viewcache != "" { m.ctx.Logger.Debugln("Cached View()") m.textarea.SetWidth(m.viewcacheTextareaXY[2])