Skip to content

Commit

Permalink
🐛 Fix saved config overwriting authors
Browse files Browse the repository at this point in the history
When saving the configuration the authors field is not preserved. This
is because authors are not editable in the options and therefore are
not part of the new config struct which replaces the existing one.

Merging the old and new config structs together allows the existing
authors to be preserved. The merging library used does not merge zero
value fields.
  • Loading branch information
mikelorant committed Mar 3, 2023
1 parent c4637af commit 9656fb6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions internal/ui/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/mikelorant/committed/internal/config"
"github.com/mikelorant/committed/internal/ui/option/section"
"github.com/mikelorant/committed/internal/ui/option/setting"

"github.com/imdario/mergo"
)

func (m *Model) configureOptions() {
Expand Down Expand Up @@ -121,7 +123,7 @@ func (m *Model) CommitPaneSet() {
)
}

func (m *Model) ToConfig() config.Config {
func (m *Model) ToConfig() {
ps := m.models.option.GetPaneSets()

view := config.View{
Expand All @@ -140,8 +142,10 @@ func (m *Model) ToConfig() config.Config {
Signoff: ps["Commit"][1].(*setting.Toggle).Enable,
}

return config.Config{
cfg := config.Config{
View: view,
Commit: commit,
}

mergo.Merge(&m.state.Config, cfg)
}
2 changes: 1 addition & 1 deletion internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (m Model) onKeyPress(msg tea.KeyMsg) keyResponse {
m.previousFocus = m.focus
m.focus = optionComponent
case "ctrl+w":
m.state.Config = m.ToConfig()
m.ToConfig()
m.writeConfig = true
case "esc":
if m.focus == helpComponent || m.focus == optionComponent {
Expand Down

0 comments on commit 9656fb6

Please sign in to comment.