Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(table): add function to set cursor position #219

Merged
merged 1 commit into from Aug 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions table/table.go
Expand Up @@ -291,6 +291,12 @@ func (m Model) Cursor() int {
return m.cursor
}

// SetCursor sets the cursor position in the table.
func (m *Model) SetCursor(n int) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if MoveTo is a better name, to match MoveUp and MoveDown.

Copy link
Contributor Author

@nikaro nikaro Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used SetCursor since it matches with Cursor and the others Set* methods, and it literally sets the cursor attribute :-) But it's up to you, i don't have a preference on this, let me know if you want me to amend the commit.

m.cursor = clamp(n, 0, len(m.rows)-1)
m.UpdateViewport()
}

// MoveUp moves the selection up by any number of row.
// It can not go above the first row.
func (m *Model) MoveUp(n int) {
Expand Down