Skip to content

Commit 26ea4c6

Browse files
authored
Merge pull request docker#1522 from krissetto/hush-when-switching-to-current-theme
only change theme when actually changing theme
2 parents e309f78 + 9a97976 commit 26ea4c6

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

pkg/tui/handlers.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,12 @@ func (a *appModel) handleOpenThemePicker() (tea.Model, tea.Cmd) {
400400
}
401401

402402
func (a *appModel) handleChangeTheme(themeRef string) (tea.Model, tea.Cmd) {
403+
// Skip if selecting the already-persisted theme - preview already applied it visually,
404+
// so no need for notification, cache invalidation, or re-persisting.
405+
if styles.GetPersistedThemeRef() == themeRef {
406+
return a, nil
407+
}
408+
403409
// Load and apply the theme
404410
theme, err := styles.LoadTheme(themeRef)
405411
if err != nil {
@@ -424,6 +430,11 @@ func (a *appModel) handleChangeTheme(themeRef string) (tea.Model, tea.Cmd) {
424430

425431
// handleThemePreview applies a theme temporarily for live preview (without persisting).
426432
func (a *appModel) handleThemePreview(themeRef string) (tea.Model, tea.Cmd) {
433+
// Skip if already on this theme - no need to invalidate caches
434+
if current := styles.CurrentTheme(); current != nil && current.Ref == themeRef {
435+
return a, nil
436+
}
437+
427438
// Load and apply the theme (without persisting)
428439
theme, err := styles.LoadTheme(themeRef)
429440
if err != nil {
@@ -439,6 +450,11 @@ func (a *appModel) handleThemePreview(themeRef string) (tea.Model, tea.Cmd) {
439450

440451
// handleThemeCancelPreview restores the original theme when the user cancels the theme picker.
441452
func (a *appModel) handleThemeCancelPreview(originalRef string) (tea.Model, tea.Cmd) {
453+
// Skip if already on the original theme - no need to invalidate caches
454+
if current := styles.CurrentTheme(); current != nil && current.Ref == originalRef {
455+
return a, nil
456+
}
457+
442458
// Load and apply the original theme
443459
theme, err := styles.LoadTheme(originalRef)
444460
if err != nil {

pkg/tui/styles/theme.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,21 @@ func SaveThemeToUserConfig(themeRef string) error {
346346
return nil
347347
}
348348

349+
// GetPersistedThemeRef returns the theme reference persisted in user config.
350+
// Returns DefaultThemeRef if no theme is set or if loading fails.
351+
func GetPersistedThemeRef() string {
352+
cfg, err := userconfig.Load()
353+
if err != nil {
354+
return DefaultThemeRef
355+
}
356+
357+
if cfg.Settings == nil || cfg.Settings.Theme == "" {
358+
return DefaultThemeRef
359+
}
360+
361+
return cfg.Settings.Theme
362+
}
363+
349364
// listThemeRefsFrom lists theme refs from a specific directory (for testing).
350365
// It only returns theme refs found in the directory, without adding any defaults.
351366
func listThemeRefsFrom(dir string) ([]string, error) {

0 commit comments

Comments
 (0)