diff --git a/wdgt_linear_layout.go b/wdgt_linear_layout.go index f9725be..7cd0e40 100644 --- a/wdgt_linear_layout.go +++ b/wdgt_linear_layout.go @@ -130,7 +130,6 @@ func (w *LinearLayout) HandleKey(ev *tcell.EventKey) bool { } active := w.findActive() if active != nil { - w.Log("LL(%s) Active(%s) Handlekey", w.Id(), active.Id()) if active.HandleKey(ev) { return true } @@ -504,6 +503,7 @@ func (w *LinearLayout) updateLLHWidgetSize(wd Widget) { if w.stacked { rH = wd.MinH() } + w.Log("(%s) Resize (%s): X:%d, Y:%d", w.Id(), wd.Id(), w.getWeightedW(wd), rH) wd.HandleResize((&Coord{X: w.getWeightedW(wd), Y: rH}).ResizeEvent()) } @@ -562,6 +562,11 @@ func (w *LinearLayout) updateLLVWidgetPos(wd Widget) { } func (w *LinearLayout) updateLLHWidgetPos(wd Widget) { + debug := func(wd Widget, txt string, args ...any) { + if wd.Id() == "mngenc.selectadversary" { + w.Log(txt, args...) + } + } c := Coord{} for i := range w.widgets { if w.widgets[i] == wd { @@ -572,6 +577,7 @@ func (w *LinearLayout) updateLLHWidgetPos(wd Widget) { } if w.widgets[i].Visible() { c.X = w.widgets[i].GetX() + w.widgets[i].GetW() + debug(wd, "Bumping X: %d + %d = %d", w.widgets[i].GetX(), w.widgets[i].GetW(), c.X) } } @@ -608,6 +614,7 @@ func (w *LinearLayout) updateLLHWidgetPos(wd Widget) { c.X += 1 c.Y += 1 } + w.Log("(%s) SetPos (%s): X:%d, Y:%d", w.Id(), wd.Id(), c.X, c.Y) wd.SetPos(c) } diff --git a/wdgt_searcher.go b/wdgt_searcher.go index a039911..f6a36c7 100644 --- a/wdgt_searcher.go +++ b/wdgt_searcher.go @@ -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]) } } diff --git a/wdgt_simple_list.go b/wdgt_simple_list.go index 03c9fee..c31ecab 100644 --- a/wdgt_simple_list.go +++ b/wdgt_simple_list.go @@ -22,6 +22,7 @@ THE SOFTWARE. package widgets import ( + h "git.bullercodeworks.com/brian/tcell-widgets/helpers" wh "git.bullercodeworks.com/brian/tcell-widgets/helpers" "github.com/gdamore/tcell" ) @@ -235,9 +236,7 @@ func (w *SimpleList) WantH() int { func (w *SimpleList) MinW() int { lng := wh.Longest(w.list) - if lng > 80 { - lng = 80 - } + lng = h.Min(lng, 80) return 2 + lng } @@ -252,6 +251,9 @@ func (w *SimpleList) MoveUp() bool { } return true } else if w.cursorWrap { + if w.cursor <= 0 { + return false + } w.cursor = len(w.list) - 1 if w.onChange != nil { w.onChange(w.cursor, w.list[w.cursor]) @@ -270,7 +272,7 @@ func (w *SimpleList) MoveDown() bool { return true } else if w.cursorWrap { w.cursor = 0 - if w.onChange != nil { + if len(w.list) > w.cursor && w.onChange != nil { w.onChange(w.cursor, w.list[w.cursor]) } return true