fix initial selection/highlighting issue

This commit is contained in:
2023-02-20 21:16:33 -08:00
parent c1e69b62f1
commit c9db6e38e4

View File

@@ -109,12 +109,7 @@ func (m CommitLog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
switch msg.String() { switch msg.String() {
case "j": case "j", "k", "b", "n", "pgdown", "pgup":
m.Table.MoveDown(1)
return m, nil
case "k":
m.Table.MoveUp(1)
return m, nil
default: default:
mr := commits.RepoSet(m.Repos) mr := commits.RepoSet(m.Repos)
cis, _ := mr.GetRepoCommits(m.Year, m.Authors) cis, _ := mr.GetRepoCommits(m.Year, m.Authors)
@@ -132,6 +127,7 @@ func (m CommitLog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
rows = append(rows, r) rows = append(rows, r)
} }
m.Table.SetRows(rows) m.Table.SetRows(rows)
m.Table.SetCursor(0)
} }
} }
var cmd tea.Cmd var cmd tea.Cmd
@@ -147,7 +143,6 @@ func newTable() table.Model {
{Title: "Author", Width: 15}, {Title: "Author", Width: 15},
{Title: "Message", Width: 40}, {Title: "Message", Width: 40},
}) })
t.SetCursor(0)
t.KeyMap.LineUp = key.NewBinding(key.WithKeys("k"), t.KeyMap.LineUp = key.NewBinding(key.WithKeys("k"),
key.WithHelp("k", "move up one commit")) key.WithHelp("k", "move up one commit"))
t.KeyMap.LineDown = key.NewBinding(key.WithKeys("j"), t.KeyMap.LineDown = key.NewBinding(key.WithKeys("j"),
@@ -270,6 +265,7 @@ func NewCommitLog() (CommitLog, error) {
if err != nil { if err != nil {
return m, err return m, err
} }
m.Table.SetCursor(0)
return m, err return m, err
} }