summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context/filtered_list.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-06-03 12:12:32 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-03 12:54:14 +1000
commitb8bee4de5158a6f285127eff018c442bf45ae970 (patch)
tree04f5a1fc634e7d8e5cf02f653e47e4d9c23113c5 /pkg/gui/context/filtered_list.go
parentd67b209e62f8254d5f17ecdb8fe7ff810f000566 (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.go14
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]
+}