▍ humdrum codex / glint v1.0.2
license AGPL-3.0

fix: re-render the open preview on theme cycle (dark mode showed a light block)

035eb3281c7850b1caa2f750b92f487c5e9503c5
humdrum <me@humdrum.me> · 2026-06-28 17:13

parent 03fcb12b

fix: re-render the open preview on theme cycle (dark mode showed a light block)

cycleTheme updated the glamour style but left an already-open preview rendered
in the previous theme's style — cycling to flexoki-dark while previewing showed
glamour's light document background on the dark canvas. Re-render the preview
when cycling in preview mode; add a Style() getter + regression test.

3 files changed

internal/app/app.go +5 −0
@@ -312,6 +312,11 @@ func (a *App) cycleTheme() (tea.Model, tea.Cmd) {
 	a.theme = theme.Next(a.theme.Name)
 	a.editor.SetTheme(a.theme)
 	a.preview.SetStyle(a.glamourStyle())
+	// Re-render an open preview so its glamour style follows the new theme
+	// (otherwise it keeps the old light/dark block until the next toggle).
+	if a.mode == ModePreview {
+		_ = a.preview.Render(string(a.editor.Bytes()))
+	}
 	if a.picker != nil {
 		a.picker.SetTheme(a.theme)
 		a.picker.SetStyle(a.glamourStyle())
internal/app/app_test.go +20 −0
@@ -491,3 +491,23 @@ 	if got := string(a.editor.Bytes()); got != "" {
 		t.Errorf("editor not blank: %q", got)
 	}
 }
+
+func TestCycleThemeReRendersOpenPreview(t *testing.T) {
+	cfg := config.Default()
+	a := New(cfg)
+	a.theme = theme.FlexokiLight() // start light
+	a.preview.SetStyle("light")
+	a.Update(tea.WindowSizeMsg{Width: 80, Height: 24})
+	a.editor.SetContent([]byte("# hi"))
+	a.Update(tea.KeyMsg{Type: tea.KeyCtrlP}) // open preview (light)
+	if a.mode != ModePreview {
+		t.Fatalf("expected preview mode")
+	}
+	a.Update(tea.KeyMsg{Type: tea.KeyCtrlT}) // cycle → flexoki-dark
+	if a.theme.Name != "flexoki-dark" {
+		t.Fatalf("theme = %q, want flexoki-dark", a.theme.Name)
+	}
+	if got := a.preview.Style(); got != "dark" {
+		t.Errorf("preview style after cycle = %q, want dark (re-rendered)", got)
+	}
+}
internal/preview/preview.go +3 −0
@@ -101,3 +101,6 @@ }
 
 // View renders the viewport.
 func (m *Model) View() string { return m.vp.View() }
+
+// Style returns the current glamour style (used in tests).
+func (m *Model) Style() string { return m.style }