diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-06-03 12:12:32 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-03 12:54:14 +1000 |
commit | b8bee4de5158a6f285127eff018c442bf45ae970 (patch) | |
tree | 04f5a1fc634e7d8e5cf02f653e47e4d9c23113c5 /pkg/gui/context/filtered_list.go | |
parent | d67b209e62f8254d5f17ecdb8fe7ff810f000566 (diff) |
Scroll to top when filtering and retain selection when cancelling filter
Diffstat (limited to 'pkg/gui/context/filtered_list.go')
-rw-r--r-- | pkg/gui/context/filtered_list.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/pkg/gui/context/filtered_list.go b/pkg/gui/context/filtered_list.go index b848b96d4..bffd0eddb 100644 --- a/pkg/gui/context/filtered_list.go +++ b/pkg/gui/context/filtered_list.go @@ -68,3 +68,17 @@ func (self *FilteredList[T]) applyFilter() { func (self *FilteredList[T]) match(haystack string, needle string) bool { return utils.CaseInsensitiveContains(haystack, needle) } + +func (self *FilteredList[T]) UnfilteredIndex(index int) int { + if self.filteredIndices == nil { + return index + } + + // we use -1 when there are no items + if index == -1 { + return -1 + } + + // TODO: mutex + return self.filteredIndices[index] +} |