Some work
This commit is contained in:
@@ -41,12 +41,13 @@ type Searcher struct {
|
||||
visible bool
|
||||
focusable bool
|
||||
|
||||
title string
|
||||
search *Field
|
||||
data []string
|
||||
filteredData []string
|
||||
cursor int
|
||||
disableBorder bool
|
||||
title string
|
||||
search *Field
|
||||
data []string
|
||||
filteredData []string
|
||||
filteredToTrue map[int]int
|
||||
cursor int
|
||||
disableBorder bool
|
||||
|
||||
selectFunc func(idx int, s string) bool
|
||||
onChange func(idx int, s string) bool
|
||||
@@ -84,6 +85,7 @@ func (w *Searcher) Init(id string, style tcell.Style) {
|
||||
})
|
||||
w.customKeyMap = BlankKeyMap()
|
||||
w.focusable = true
|
||||
w.filteredToTrue = make(map[int]int)
|
||||
}
|
||||
|
||||
func (w *Searcher) Id() string { return w.id }
|
||||
@@ -332,6 +334,7 @@ func (w *Searcher) SetData(data []string) {
|
||||
func (w *Searcher) updateFilter() {
|
||||
var selVal string
|
||||
data := []string{}
|
||||
w.filteredToTrue = make(map[int]int)
|
||||
copy(data, w.filteredData)
|
||||
if len(data) > 0 && len(data) > w.cursor {
|
||||
selVal = data[w.cursor]
|
||||
@@ -342,10 +345,12 @@ func (w *Searcher) updateFilter() {
|
||||
for i := range w.data {
|
||||
if cS {
|
||||
if strings.Contains(w.data[i], filter) {
|
||||
w.filteredToTrue[len(w.filteredData)] = i
|
||||
w.filteredData = append(w.filteredData, w.data[i])
|
||||
}
|
||||
} else {
|
||||
if strings.Contains(strings.ToLower(w.data[i]), filter) {
|
||||
w.filteredToTrue[len(w.filteredData)] = i
|
||||
w.filteredData = append(w.filteredData, w.data[i])
|
||||
}
|
||||
}
|
||||
@@ -379,7 +384,12 @@ func (w *Searcher) doChange() {
|
||||
return
|
||||
}
|
||||
if w.cursor < l {
|
||||
w.onChange(w.cursor, w.filteredData[w.cursor])
|
||||
tr, ok := w.filteredToTrue[w.cursor]
|
||||
if !ok {
|
||||
// How did we get here?
|
||||
return
|
||||
}
|
||||
w.onChange(tr, w.data[tr])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user