diff --git a/dropdown.go b/dropdown.go index d3c24d1..b201be0 100644 --- a/dropdown.go +++ b/dropdown.go @@ -254,8 +254,14 @@ func (d *DropDown) Draw(screen tcell.Screen) { lwidth := maxWidth lheight := len(d.options) _, sheight := screen.Size() - if ly+lheight >= sheight && ly-lheight-1 >= 0 { + if ly+lheight >= sheight && ly-2 > lheight-ly { ly = y - lheight + if ly < 0 { + ly = 0 + } + } + if ly+lheight >= sheight { + lheight = sheight - ly } d.list.SetRect(lx, ly, lwidth, lheight) d.list.Draw(screen) diff --git a/list.go b/list.go index 73a82c7..a045fc1 100644 --- a/list.go +++ b/list.go @@ -193,8 +193,24 @@ func (l *List) Draw(screen tcell.Screen) { } } + // We want to keep the current selection in view. What is our offset? + var offset int + if l.showSecondaryText { + if l.currentItem >= height/2 { + offset = l.currentItem + 1 - (height / 2) + } + } else { + if l.currentItem >= height { + offset = l.currentItem + 1 - height + } + } + // Draw the list items. for index, item := range l.items { + if index < offset { + continue + } + if y >= bottomLimit { break }