Skip to content

Commit

Permalink
Add SetFilterText and SetFilterState methods
Browse files Browse the repository at this point in the history
  • Loading branch information
blvrd committed Sep 10, 2024
1 parent c45e80a commit 8043996
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,34 @@ func (m *Model) SetFilteringEnabled(v bool) {
m.updateKeybindings()
}

// SetFilterText explicitly sets the filter text without relying on user input.
// It also sets the filterState to a sane default of FilterApplied, but this
// can be changed with SetFilterState

Check failure on line 263 in list/list.go

View workflow job for this annotation

GitHub Actions / lint-soft

Comment should end in a period (godot)
func (m *Model) SetFilterText(filter string) {
m.filterState = Filtering
m.FilterInput.SetValue(filter)
cmd := filterItems(*m)
msg := cmd()
fmm, _ := msg.(FilterMatchesMsg)
m.filteredItems = filteredItems(fmm)
m.filterState = FilterApplied
m.Paginator.Page = 0
m.cursor = 0
m.FilterInput.CursorEnd()
m.updatePagination()
m.updateKeybindings()
}

// Helper method for setting the filtering state manually

Check failure on line 279 in list/list.go

View workflow job for this annotation

GitHub Actions / lint-soft

Comment should end in a period (godot)
func (m *Model) SetFilterState(state FilterState) {
m.Paginator.Page = 0
m.cursor = 0
m.filterState = state
m.FilterInput.CursorEnd()
m.FilterInput.Focus()
m.updateKeybindings()
}

// FilteringEnabled returns whether or not filtering is enabled.
func (m Model) FilteringEnabled() bool {
return m.filteringEnabled
Expand Down

0 comments on commit 8043996

Please sign in to comment.