do not select entries outside of the view

pull/137/head
Simon Let 6 years ago
parent e5a2279505
commit 52fc74c588
  1. 18
      cmd/cli/main.go

@ -156,11 +156,12 @@ func runReshCli() (string, int) {
} }
type state struct { type state struct {
lock sync.Mutex lock sync.Mutex
cliRecords []records.CliRecord cliRecords []records.CliRecord
data []item data []item
rawData []rawItem rawData []rawItem
highlightedItem int highlightedItem int
displayedItemsCount int
rawMode bool rawMode bool
@ -316,10 +317,9 @@ func (m manager) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier)
} }
func (m manager) Next(g *gocui.Gui, v *gocui.View) error { func (m manager) Next(g *gocui.Gui, v *gocui.View) error {
_, y := g.Size()
m.s.lock.Lock() m.s.lock.Lock()
defer m.s.lock.Unlock() defer m.s.lock.Unlock()
if m.s.highlightedItem < y { if m.s.highlightedItem < m.s.displayedItemsCount-1 {
m.s.highlightedItem++ m.s.highlightedItem++
} }
return nil return nil
@ -447,6 +447,8 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error {
selectedCommand := m.s.data[m.s.highlightedItem].cmdLine selectedCommand := m.s.data[m.s.highlightedItem].cmdLine
var selectedLineCount int = len(selectedCommand)/(printedLineLength) + 1 var selectedLineCount int = len(selectedCommand)/(printedLineLength) + 1
m.s.displayedItemsCount = maxY - topBoxSize - selectedLineCount
for i, itm := range m.s.data { for i, itm := range m.s.data {
if i == maxY-topBoxSize-selectedLineCount { if i == maxY-topBoxSize-selectedLineCount {
if debug { if debug {
@ -509,6 +511,8 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error {
func (m manager) rawMode(g *gocui.Gui, v *gocui.View) error { func (m manager) rawMode(g *gocui.Gui, v *gocui.View) error {
maxX, maxY := g.Size() maxX, maxY := g.Size()
topBoxSize := 3
m.s.displayedItemsCount = maxY - topBoxSize
for i, itm := range m.s.rawData { for i, itm := range m.s.rawData {
if i == maxY { if i == maxY {

Loading…
Cancel
Save