commit autocomplete automatically on up/down
This commit is contained in:
parent
556ebcd9c6
commit
6ed2f36928
@ -28,10 +28,16 @@ func (view *Settings) Event(state *ui.State, event vaxis.Event) (processed bool)
|
||||
case "Ctrl+c", "Ctrl+d":
|
||||
close(ui.Quit)
|
||||
case "Up":
|
||||
if view.index == 3 {
|
||||
view.inputs[2].Update(event)
|
||||
}
|
||||
if view.index > 0 {
|
||||
view.index--
|
||||
}
|
||||
case "Down":
|
||||
if view.index == 3 {
|
||||
view.inputs[2].Update(event)
|
||||
}
|
||||
if view.index < 4 {
|
||||
view.index++
|
||||
}
|
||||
|
@ -13,9 +13,7 @@ type Input struct {
|
||||
Placeholder string
|
||||
}
|
||||
|
||||
func (m *Input) Draw(win vaxis.Window) {
|
||||
// figure out which thing to complete
|
||||
rest := ""
|
||||
func complete(m *Input) (rest string) {
|
||||
if m.model.String() != "" {
|
||||
for _, comp := range m.AutoComplete {
|
||||
if strings.HasPrefix(comp, m.model.String()) {
|
||||
@ -26,11 +24,25 @@ func (m *Input) Draw(win vaxis.Window) {
|
||||
} else {
|
||||
rest = m.Placeholder
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (m *Input) Draw(win vaxis.Window) {
|
||||
// figure out which thing to complete
|
||||
rest := complete(m)
|
||||
m.model.Draw(win)
|
||||
win.New(len(m.model.String()), 0, win.Width, win.Height).Print(vaxis.Segment{Text: rest, Style: vaxis.Style{Foreground: vaxis.IndexColor(8)}})
|
||||
}
|
||||
|
||||
func (m *Input) Update(event vaxis.Event) {
|
||||
if key, ok := event.(vaxis.Key); ok && key.EventType == vaxis.EventPress {
|
||||
switch key.String() {
|
||||
case "Up", "Down":
|
||||
if m.model.String() != "" {
|
||||
m.model.SetContent(m.model.String() + complete(m))
|
||||
}
|
||||
}
|
||||
}
|
||||
m.model.Update(event)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user